NET/MASTER Network Control Language (NCL) Programmer's Guide
Single and Repetitive Execution
Controlling Execution Flow
106160 Tandem Computers Incorporated 5–19
Controlling Runaway DO Loops
The keyword FOREVER implies that a DO loop executes indefinitely. This is not so in
practice. If there is no condition that terminates execution, the loop executes to the
maximum value of the system variable &SYS.LOOPCTL (the default value of this
variable is 1000). It is normal practice, however, to specify a condition to terminate the
execution of a repetitive DO loop before the maximum value of &SYS.LOOPCTL is
reached.
You can use the system variable &SYS.LOOPCTL to protect against uncontrolled
looping or to set an exit condition from a loop.
When an NCL procedure begins execution, &SYS.LOOPCTL is assigned the value of
1000 by default. The value of the variable is decremented by 1 after each pass through
the loop.
Note The GOTO and GOSUB core statements also decrement &SYS.LOOPCTL by 1. This allows you to
control runaway branching.
If the count reaches 0, a run-time error is raised that you can trap using either the
ERROR or LOOPING_ERROR error handler. These error handlers are discussed in
Section 7, “Run-Time Error Handling.”
The following example assigns a value of 2000 to &SYS.LOOPCTL:
&SYS.LOOPCTL = 2000
Note The CNMREAD, EMSREAD, INTREAD, LOGREAD, and MSGREAD verbs reset the value of
&SYS.LOOPCTL to its default value of 1000 each time they are executed (unless it is explicitly set to 0 or
to a number greater than 1000 by the NCL process). These verbs are used in long-running, looping
procedures that read messages. The verbs can read many messages in a single DO loop.
Nesting DO Loops You can nest DO loops. The syntax of nested DO loops is the following:
DO …
statement1
statement2
statement3
…
DO …
statement4
statement5
statement6
…
END
…
END