Use the FOR statement to specify that a group of statements (entered after DO up to END_FOR ) is to be executed repeatedly, while a progression of values is assigned to the control variable of the FOR statement (entered after FOR ). The FOR statement increments the control variable up or down from the initial value (assigned to the control variable) to the final value (entered after TO ) in increments determined by the value of an expression (entered after BY ). If the BY construct is omitted, the increment value defaults to 1 .
The iteration of the FOR statement is terminated when the value of the control variable is outside the range specified by the TO construct. The termination condition is checked at the beginning of each increment resp. decrement iteration: The group of statements will not be executed, if the value of the control variable has exceeded the final value (in case of a positive increment value) resp. if the value of the control variable has fallen below the final value (in case of a negative increment value).
The value of the control variable after completion of the FOR statement corresponds to the last value of the last iteration (hence: to the final value). If the group of statements is not executed at all, the value of the control variable is not changed.
The control variable, initial value and final value must be expressions of the same integer type ANY_INT (e.g. INT , SINT or DINT ) and must not be altered by any of the repeated statements. In contrast to that, it is possible to use a different integer type for the increment value. This makes it possible to decrement an initial value while using a control variable of an ANY_UNSIGNED datatype (see example 2).
No changes for control variable, initial value, final value and increment value within the repeated statements
Observe that Neuron Power Engineer determines the number of the increment iterations before the FOR statement is started. Hence, do not enter any statements after DO up to END_FOR that change the expressions for the control variable, initial value, final value and/or increment value.
|
Indeterminable number of the increment iterations
If the number of the increment iterations is indeterminable (see example 4 because it is impossible to reach the final value in this example), the FOR statement is not started at all.
|
|