FOR
8.3
The FOR instruction allows structured looping in a PL/B program. The instruction uses the following format:
|
|
|
|
|
Where:
label
Optional. A Program Execution Label.
target
Required. A Numeric Variable that serves as the target for the loop.
sep
Required. A comma or one of the following prepositions: BY, TO, OF, FROM, USING, WITH, IN, or INTO.
start
Required. A Numeric Variable, literal, decimal constant or expression that is assigned to the target variable as the looping is initiated.
end
Required. A Numeric Variable, literal, decimal constant or expression that specifies the ending value of the target.
incr
Optional. A Numeric Variable, literal, constant or expression that specifies the increment value of the target variable for each iteration of the loop.
Flags Affected: NONE
Note the following:
The FOR statement is a program control statement that requires a REPEAT as a loop terminating statement.
Upon initial entry into the FOR statement loop, the {start} value is assigned to the {target} variable. Upon subsequent loops through the FOR statement the {target} value is incremented by the value of the {incr} operand.
If the {incr} operand is not specified, the default incrementing value is one (1).
The FOR loop processing starts with the {start} value and continues through the {end} value inclusively. If the {incr} value is positive, the FOR statement loop will terminate when {end} is greater than {target}. If the {incr} value is negative, the FOR statement loop will terminate when {end} is less than {target}.
The FILEPI count is not affected by the FOR statement execution.
Executing a GOTO in a FOR statement loop is not recommended. If this is done, indeterminate FOR loop program processing can be expected.
The FOR statement can be nested thirty-two (32) levels deep. The FOR statement is implemented as a LOOP statement operation. This means LOOP/REPEAT and FOR/REPEAT constructs combined have a limit of thirty-two nested levels.
The FOR statement termination can occur upon initial entry should the initial {start} and {end} values meet the termination criteria.
See Also: Example Code, Program Control Instructions
![]() |