Function
The GO TO statement is used to transfer control from one part of the Procedure Division to another.
Format 1 Format 2 | of the GO TO statement passes control to a specific procedure. of the GO TO statement passes control to one of a series of specified procedures, depending on the value of a data item. |
Format 1
GO TO [ procedure-name ]
Syntax rules
If the GO TO statement appears in a consecutive sequence of imperative statements within a sentence, it must appear as the last statement within that sequence.
A GO TO statement referenced by an ALTER statement must be preceded by a paragraph-name, and it must be the only statement in this paragraph (see section "ALTER statement").
A GO TO statement without specification of procedure-name must be preceded by a paragraph-name, and it must be the only statement in this paragraph.
General rules
When a GO TO statement is executed, control is transferred to procedure-name.
If procedure-name is not specified, an ALTER statement, referring to this GO TO statement, must be executed prior to the execution of this GO TO statement.
A GO TO statement in which procedure-name is not specified must be supplied with a procedure-name destination by the ALTER statement. Otherwise, the program will terminate with error message 9142.
Example 8-40
GO TO END-ROUTINE. ... END-ROUTINE. CLOSE CARD-FILE, PRINTER-FILE. STOP RUN.
In this example, the GO TO statement transfers control to the procedure named END-ROUTINE; the CLOSE statement is executed immediately after the GO TO statement.
Format 2
GO TO {procedure-name-1}...
DEPENDING ON identifier
Syntax rule
identifier is the name of an elementary numeric data item described as an integer. The USAGE must be either DISPLAY, COMPUTATIONAL, COMPUTATIONAL-5, BINARY, COMPUTATIONAL-3 or PACKED-DECIMAL.
General rule
When a GO TO statement is executed, control is transferred to procedure-name-1..., depending on the value of the identifier, which may be 1, 2, ... n.
If the identifier has any value other than 1, 2, ... n, no transfer of control takes place, and processing continues with the next statement in the normal sequence for execution (n represents the specified number of procedure-names).
Example 8-41
77 A PICTURE 9. ... MOVE 3 TO A. ... GO TO X-PAR Y-PAR Z-PAR DEPENDING ON A.
Since the value of A is 3 when the GO TO statement is executed, control is transferred to Z-PAR, the third procedure-name in the series.