NET/MASTER Network Control Language (NCL) Programmer's Guide

Single and Repetitive Execution
Controlling Execution Flow
5–8 106160 Tandem Computers Incorporated
Note Since there is no condition that terminates the DO loop in this example, the DO loop executes to the
maximum value of the system variable &SYS.LOOPCTL (the default value of this variable is 1000) and
terminates with a LOOPING_ERROR run-time error. The &SYS.LOOPCTL system variable is discussed
later in this section. The LOOPING_ERROR error handler is discussed in Section 7, “Run-Time Error
Handling.”
Using a Control Variable With the TO Keyword. The TO keyword sets the termination value
of the control variable in a repetitive DO loop. The syntax of a DO loop that uses the
TO keyword with a control variable is the following:
DO
cvar
=
expri
TO
exprt
[ BY
exprb
] [ FOR
exprf
]
statement1
statement2
statement3
END
exprt
specifies an expression that must evaluate to a number. It does not have to be an
integer and it can be either a positive or negative number. This gives the value
you want the control variable to have the last time through the loop. The
expression is evaluated when the loop is entered.
Note NCL assumes a positive value of 1 for the increment even when the starting value of the control variable
is greater than the value after the TO keyword. In this case, the loop is not executed.
The following example shows an NCL procedure that uses a control variable with the
TO keyword in a DO loop:
zex0505n: PROCEDURE
/* DO loop with the TO keyword */
DO &control = 1 TO &1
SAY &control
END
SAY "The final value of &control is "&control
END zex0505n
The initial value of the control variable, &CONTROL, is 1. The value given to
&CONTROL the last time through the loop is determined by the value of the
parameter &1. The value of &1 is determined by the value that is passed to the
procedure when it is executed.