If statements, If-else statements, While statements – Teledyne LeCroy Merlins Wand - Users Manual User Manual

Page 286: If-else, While

Advertising
background image

270

CATC M

ERLIN

S

W

AND

2.00

C

HAPTER

D

User’s Manual

CATC Scripting Language

The variable expression statement is also called an assignment statement,
because it assigns a value to a variable.

if

Statements

An if statement follows the form

if <expression> <statement>

For example,

if (3 && 3) Trace("True!");

will cause the program to evaluate whether the expression 3 && 3 is
nonzero, or True. It is, so the expression evaluates to True and the Trace
statement will be executed. On the other hand, the expression 3 && 0 is
not nonzero, so it would evaluate to False, and the statement wouldn't be
executed.

if-else

Statements

The form for an if-else statement is

if <expression> <statement1>
else <statement2>

The following code

if ( 3 - 3 || 2 - 2 ) Trace ( "Yes" );
else Trace ( "No" );

will cause "No" to be printed, because 3 - 3 || 2 - 2 will evaluate to
False (neither 3 - 3 nor 2 - 2 is nonzero).

while

Statements

A while statement is written as

while <expression> <statement>

An example of this is

x = 2;
while ( x < 5 )
{

Trace ( x, ", " );
x = x + 1;

}

The result of this would be

Advertising