<< Click to Display Table of Contents >> Navigation: »No topics above this level« FOR statement |
mapp Services V5.16
Statements can be executed repeatedly with the FOR statement.
FOR <control_variable> := <expression1> TO <expression2> BY <expression3> DO
<statement_list>
END_FOR;
A FOR statement is executed as shown below:
•Control variable <control_variable> is assigned value <expression1>.
•If the <expression3> increment is positive, the FOR statement will be exited when control variable <control_variable> is greater than <expression2>. If the <expression3> increment is negative, the FOR statement will be exited when control variable <control_variable> is less than <expression2>.
•The statements in <statement_list> are executed.
•The value of increment <expression3> is added to control variable <control_variable>.
•Go to step 2.
The value of control variable <control_variable> is checked before the statements in <statement_list> are executed, meaning that it is possible that the statements are never executed.
Whenever the statements in <statement_list> are executed, control variable <control_variable> is increased by increment <expression3>. If the increment is positive, the control variable is increased in each cycle; if the increment is negative, the control variable is decreased in each cycle.
The step does not need to be specified. If it is not present, a step value of 1 is used.
Var2 := 1;
FOR Var1 := 1 TO 5 BY 1 DO
Var2 := Var2 * 2;
END_FOR;
After execution of the FOR loop, "Var2" has the value 32.