The statement block is repeated while a control variable is modified and compared to a limit value (before each beginning of the statement block).
The statement block is run for each one of the values successively taken by the control variable. The initial value is assigned to the control variable during the first entry in the 对于 statement.
An optimized syntax is available: this syntax prevents the end value and/or the step value from being re-evaluated at each iteration (useful for a loop on the number of table rows for example).
This feature is available in Windows Store apps mode.
信息（Subscript） // Subscript is set to 6
// Optimized syntax
// Browse the table rows.
// The number of rows is calculated once only
对于 <Control variable> = <Initial value> TO <Final value> [STEP <x>]
Marks the beginning of the statement block.
Scalar simple variable (integer or real).
There is no need to declare this variable. Indeed, this variable is automatically declared.
Initial value of the control variable (integer or real).
Final value of the control variable (integer or real).
Increment step (optional) of the control variable (1 by default).
Optional value of the increment step (same type as the type of the control variable).
Marks the end of the statement block.
Other possible syntaxes 隐藏详细信息
对于 <Control Variable> = <Initial Value> _TO_ <Final Value> [STEP <x>]
FOR <Control Variable> = <Initial Value> _TO_ <Final Value> [_STEP_ <x>]
FOR <Control Variable> = <Initial Value> TO <Final Value> [_STEP_ <x>]
Signals that the final value must be evaluated once only
Signals that the increment step must be evaluated once only.
You also have the ability to use the following syntax:
FOR <Control Variable> = <Initial Value> TO <Final Value> [STEP <x>]; ... ; END
The semicolon is used to separate the different lines.
Code to run
The code to run is located between the 对于
The increment step of the 对于
statement must be constant. A warning is displayed during the project compilation if the increment step is likely to change at each iteration.
Exiting from a FOR loop
Several statements are available:
- 返回 statement: Exits from the 对于 loop and exits from the current process (or procedure).
- 返回 statement: Return a status report to the calling process. Exits from the 对于 loop and exits from the current process (or procedure).
- 跳出 statement/"跳出:" label: Exits the 对于 loop and run the rest of the current process.
is used to exit from the 对于
loop and to close the current window.
Caution: 返回 statement and 返回 statement cannot be used in the same process.
Running the next iteration
To directly run the next iteration without ending the code of the next iteration
, use the 继续 statement / "继续:" label
FOR <Control variable> = <Initial value> TO <Final value> [STEP <x>]
IF <Condition> THEN CONTINUE // Return to the FOR keyword
In this case, the control variable is automatically incremented.