Repeats a group of statements a specified number of times.
for (statement1; statement2; statement3)
command consists of three parts separated by semicolon:
- It defines the initial numeric value of the variable used as cycle counter. For example:
- Logical expression that is evaluated ata the beginning of each cycle iteration. If the expression returns true
then the iteration is completed, otherwise the cycle is exited.
It is usualy a simpe test whether the cycle counter is within the defined range.
i < 20
- This command is executed at the end of each iteration. It is usualy an incrementation (or decrementation) of corresponding cycle variable. For example:
: Change of the i
value inside the cycle may render the code hard to read and tune.
can only be used within a switch
control structure to provide an alternate way to exit. Any number of break
statements may be placed anywhere in the loop.
For similar purpose in the VBScript language
is used the command For...Next
A simple cycle example. It dumps text i=1
into the Debug_info
item of the INFO system.
You can nest For...Next loops by placing one For...Next loop within another. Give each loop a unique variable name as its counter. The following construction is correct:
Pm.Debug("i=" + i + ", j=" + j + ", k=" + k);