Return statements – Teledyne LeCroy CATC Scripting Language Reference Manual User Manual
Page 26

C
HAPTER
7
Statements
CATC Scripting Language
22
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 = 2 is 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 is increased to 3. Now,
x < 5
is 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 < 5
is true, so 4 and a new line are printed by the Trace statement. Next, the
value of x increases to 5. 5 < 5 is 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
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 there” as 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,