NET/MASTER Network Control Language (NCL) Reference Manual

GOSUB
Core Statements
2–26 106126 Tandem Computers Incorporated
Considerations
The GOSUB statement records the procedure position within the current DO
nesting environment. The DO nesting level is then cleared. This allows new DO
groups to be nested.
A GOTO statement within a GOSUB subroutine clears only the nesting levels of
DO groups initiated within the GOSUB.
The &SYS.LOOPCTL system variable has a default setting of 1000; this value
decrements by 1 each time a GOSUB statement is executed. For a detailed
discussion of system variables, see Section 5, “System Variables.” When the
variable reaches 0 (zero), NCL terminates the process. This prevents NCL
processes from uncontrolled recursive looping. You can check the value of
&SYS.LOOPCTL, and if necessary, you can alter its default initial value by using
an assignment statement. If you return from a GOSUB statement (see the RETSUB
statement, described later in this section), NCL does not restore the original value
of &SYS.LOOPCTL.
See also DO, GOTO, and RETSUB. The description of the DO core statement
indicates how the GOSUB statement affects nesting levels within DO groups. This
description also refers to the correct use of the GOSUB statement within a DO
group. The description of the GOTO core statement refers to its interaction with
the GOSUB core statement. The RETSUB core statement is used to return from a
subroutine.
Examples
The following example branches to the subroutine starting at LABEL1:
GOSUB LABEL1
The following example goes to, and returns from, a subroutine with a label determined
by the value of the &LABEL variable. If &LABEL contains the value X1 or X2, the
GOSUB statement is a multidirectional branch. If the label is not found before the
END label, execution continues from the statement after the GOSUB statement:
GOSUB &LABEL LIMIT END
/* not found falls through */
GOTO END
X1:
statement; …; RETSUB
X2:
statement; …; RETSUB
END: