While statements, For statements, While statements for statements – Teledyne LeCroy BPT - References Manual User Manual

Page 26

Advertising
background image

22

CATC S

CRIPTING

L

ANGUAGE

1.1

C

HAPTER

7

Reference Manual

Statements

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

2, 3, 4,

for

Statements

A

for

statement takes the form

for (<expression1>; <expression2>; <expression3>)
<statement>

The first expression initializes, or sets, the starting value for x. It is executed one
time, before the loop begins. The second expression is a conditional expression. It
determines whether the loop will continue -- if it evaluates true, the function keeps
executing and proceeds to the statement; if it evaluates false, the loop ends. The
third expression is executed after every iteration of the statement.

Figure 7-1: Execution of a

for

statement

Advertising