User manual

23
CHAPTER 7
CATC Scripting Language for USB Statements
The example
for(x=2;x<5;x=x+1)Trace ( x, "\n" );
would output
2
3
4
The example above works out like this: the expression x=2is executed. The
value of x is passed to x<5,resulting in 2<5. This evaluates to true, so the
statement Trace (x, "\n" ) is performed, causing 2 and a new line to print.
Next, the third expression is executed, and the value of x isincreasedto3.Now,
x<5is executed again, and is again true, so the Trace statement is executed,
causing 3 and a new line to print. The third expression increases the value of x to 4;
4<5istrue,so4andanewlineareprintedbytheTrace statement. Next, the
value of x increases to 5. 5<5is not true, so the loop ends.
return Statements
Every function returns a value, which is usually designated in a return statement.
A return statement returns the value of an expression to the calling environment.
It uses the following form:
return <expression>;
An example of a return statement and its calling environment is
Trace ( HiThere() );
...
HiThere()
{
return "Hi there";
}
The call to the primitive function Trace causes the function HiThere() to be
executed. HiThere() returns the string Hi thereas its value. This value is
passed to the calling environment (Trace), resulting in this output:
Hi there
A return statement also causes a function to stop executing. Any statements that
come after the return statement are ignored, because return transfers control
of the program back to the calling environment. As a result,