NET/MASTER Network Control Language (NCL) Reference Manual
GOSUB
Core Statements
2–24 106126 Tandem Computers Incorporated
GOSUB The GOSUB core statement registers the current position in the procedure (the
statement after the GOSUB), then branches to the statement at a specified label. The
label must not be in a DO group.
The label must be in the same scope as the current procedure or function. Unlike a
GOTO statement, the GOSUB statement does not deactivate DO groups.
To resume processing at the point after the GOSUB statement, you must use the
RETSUB core statement.
GOSUB
label
[ LIMIT
limit-expr
]
[ MATCH { EQ | GE | GT | LE | LT | NE } ]
label
specifies a label that defines a subroutine. A subroutine consists of all statements
between the
label
and the RETSUB statement.
label
must be a constant label or
an expression that equates to a legal label name, without the trailing colon (:).
See Section 8, “Compiler Operation,” for the definition of valid NCL labels.
The search for the label starts at the next statement and proceeds forward through
the procedure. If you code the label in lowercase letters, NCL converts it to
uppercase before the search.
If NCL reaches the end of the procedure before it finds the label, the search restarts
at the beginning of the procedure and continues until the current GOSUB
statement is located. The GOSUB statement cannot see PROCEDURE or
FUNCTION labels, or labels within inner or outer nested procedures or functions.
The type of label determines what happens if the label is not found. If the label is
a constant, NCL issues an error message during compilation. If the label is an
expression, NCL treats the GOSUB core statement as a NOP core statement that
performs no action.
You can use LIMIT as a label. NCL does not confuse this with the LIMIT
keyword.
LIMIT
limit-expr
specifies a constant label, or an expression that equates to a label and that restricts
the search to the first label that matches the value of
limit
-
expr
. This allows
local multidirectional branches to be specified. You can see an example of
multidirectional branching in one of the examples at the end of this description. A
multidirectional branch is a method of defining where to go (branch to) in a
procedure, based, in this case, on the literal value of some label.