NET/MASTER Network Control Language (NCL) Programmer's Guide
Explicit Branching
Controlling Execution Flow
106160 Tandem Computers Incorporated 5–39
Label Searching This subsection discusses how the GOTO, GOSUB, and SIGNAL LABEL core
statements search for labels. It outlines the search rules. It explains how to limit a
GOTO and GOSUB search with the LIMIT keyword. It explains how to use the
MATCH keyword on GOTO and GOSUB to compare labels during a search.
Rules for GOTO, GOSUB, and SIGNAL LABEL
The GOTO, GOSUB and SIGNAL LABEL core statements use the same rules to search
for a label but differ in the position at which they begin to search. The GOTO and
GOSUB statements begin to search for a target label from the following statement in
the procedure or function. The SIGNAL LABEL statement begins to search for a target
label from the first label in the procedure or function.
Hint To improve the performance of an NCL process, when searching for labels from GOTO, GOSUB, and
SIGNAL LABEL: from GOTO and GOSUB, position labels from the statement that follows the GOTO or
GOSUB; from SIGNAL LABEL, position labels from the first statement in the procedure or function. In
both cases, organize labels from the most likely match to the least likely match.
From either position, NCL searches for a target label in the same way:
1. NCL searches through all labels in sequential order inside the procedure or
function.
2. If NCL does not find a matching label, the next step depends on the reason:
a. If NCL does not find a matching label because it has reached the end of the
procedure or function, NCL wraps around to the beginning of the procedure
or function and continues to search from there.
b. If NCL does not find a matching label because it has reencountered the first
label it found after beginning to search, the search has been unsuccessful and
stops.
If NCL finds a matching label and it is legal to branch to it, then NCL branches to the
label in a manner consistent with the invoking statement and executes the statement(s)
that follow.
If NCL finds a matching label, it may be illegal to branch there. For example, it is
illegal to branch to a nested statement from a GOTO statement unless the GOTO is
executed from within the nested statement. In addition, it is illegal to branch to a label
from a GOSUB or SIGNAL LABEL statement unless the label is at the top level of the
current procedure or function. The label cannot be nested, even if the GOSUB or
SIGNAL LABEL statement is nested.
If NCL finds a matching label and it is illegal to branch to it, then NCL does not jump
to the label. If it is a constant label, you receive a compilation error. If it is an
expression, you receive a run-time error. You can trap a run-time error with an error
handler. If you do not trap the run-time error with an error handler, the procedure or
function terminates. Section 7, “Run-Time Error Handling,” explains how to trap run-
time errors.