NET/MASTER Network Control Language (NCL) Reference Manual
DO
Core Statements
106126 Tandem Computers Incorporated 2–13
If an iterative DO statement has a control variable (such as
expri
,
exprb
,
exprt
,
exprf
, or
exprr
) or any iteration control expressions, the result of evaluating
these expressions must be stored and used during loop iteration processing. The
target control variable is tested and assigned the current iteration value once in
each iteration of the loop. If an assignment is made to the control variable during
the loop, the DO group can terminate prematurely or an error can occur when
NCL tests the value of the control variable.
If an iterative DO group terminates normally, NCL does not define the value of
the control variable. If an iterative DO group terminates abnormally, NCL
preserves the current value of the control variable.
The &SYS.LOOPCTL system variable has a default setting of 1000; this value
decrements by 1 for each iteration of a loop. For a detailed discussion of system
variables, see Section 5, “System Variables.” When the variable reaches 0 (zero),
NCL terminates the NCL process. This prevents NCL processes from looping
forever. You can check the value of this system variable while iterating in a DO
group. You can also alter the default initial value by using an assignment
statement.
NCL does not reset the &SYS.LOOPCTL system variable on exit from an iterative
DO group. You must reset &SYS.LOOPCTL explicitly when it reaches 0 (zero), to
perform additional iterative processing.
The order of processing of iterative clauses within a DO group is as follows:
1. Evaluate and save the values of the control variables. Based on whether
exprb
is negative or positive and whether a control variable is specified,
calculate the logical direction of the DO statement.
2. If a control variable is specified, initialize it to
expri
.
3. Test the control variable (at the start of the DO group) against the saved
exprt
value, if specified. If the test fails (see paragraph 1 for logical
direction), terminate the group normally.
4. Decrement the saved
exprf
control variable, if specified. If
exprf
is
negative, terminate the group normally.
5. Decrement the saved
exprr
control variable, if specified. If
exprr
is
negative, terminate the group normally.
6. Evaluate
exprw
, if specified. If
exprw
is false, terminate the group normally.
7. Execute the statements inside the DO group.
8. Evaluate
expru
, if specified. If
expru
is true, terminate the group normally.
9. Add
exprb
to the control variable. This can have the effect of decrementing
the value of the control variable if
exprb
is negative.
10. Return to step 3.