For statement
Description
Executes a block of statements for as
long as a specified condition is true.
Syntax
for(init-expression;
cond-expression;
loop-expression)
statement
endfor
The for statement consists of three
optional parts, as shown in the following table:
|
Syntax Name
|
Description
|
|
init-expression
|
An expression.
This expression is executed only once, before the loop is executed.
Often used to initialize loop
indices.
|
|
cond-expression
|
A Boolean
expression. If cond-expression is true,
statement is executed. If cond-expression is false, the
loop is terminated.
|
|
loop-expression
|
An expression
is executed at the end
of each iteration of statement. Normally used to
increment loop indices.
|
|
statement
|
The statement
to be executed if cond-expression is true. Can be a
compound statement.
|
Remarks
The for loop executes statement and loop-expression repeatedly until
cond-expression
becomes false. Use the for statement to construct loops
that must execute a specified number of times. The following
example demonstrates a for loop.
intiIndex
for(iIndex
=
0;
iIndex<10;
iIndex ++)
Println(iIndex)
endfor
|