Enterprise COBOL for z/OS, V4.2, Language Reference

GO TO statement

The GO TO statement transfers control from one part of the procedure division to another. The types of GO TO statements are:

Unconditional GO TO

The unconditional GO TO statement transfers control to the first statement in the paragraph or section identified by procedure-name, unless the GO TO statement has been modified by an ALTER statement. (See ALTER statement.)

Read syntax diagramSkip visual syntax diagram
Format 1: unconditional GO TO statement

>>-GO--+----+--procedure-name-1--------------------------------><
       '-TO-'                     

procedure-name-1
Must name a procedure or a section in the same procedure division as the GO TO statement.

When the unconditional GO TO statement is not the last statement in a sequence of imperative statements, the statements following the GO TO are not executed.

When a paragraph is referred to by an ALTER statement, the paragraph must consist of a paragraph-name followed by an unconditional or altered GO TO statement.

Conditional GO TO

The conditional GO TO statement transfers control to one of a series of procedures, depending on the value of the data item referenced by identifier-1.

Read syntax diagramSkip visual syntax diagram
Format 2: conditional GO TO statement

               .------------------.                      
               V                  |                      
>>-GO--+----+----procedure-name-1-+--DEPENDING--+----+---------->
       '-TO-'                                   '-ON-'   

>--identifier-1------------------------------------------------><

procedure-name-1
Must be a procedure or a section in the same procedure division as the GO TO statement. The number of procedure-names must not exceed 255.
identifier-1
Must be a numeric elementary data item that is an integer. identifier-1 cannot be a windowed date field.

If 1, control is transferred to the first statement in the procedure named by the first occurrence of procedure-name-1.

If 2, control is transferred to the first statement in the procedure named by the second occurrence of procedure-name-1, and so forth.

If the value of identifier is anything other than a value within the range of 1 through n (where n is the number of procedure-names specified in this GO TO statement), no control transfer occurs. Instead, control passes to the next statement in the normal sequence of execution.

Altered GO TO

The altered GO TO statement transfers control to the first statement of the paragraph named in the ALTER statement.

You cannot specify the altered GO TO statement in the following:

  • A program or method that has the RECURSIVE attribute
  • A program compiled with the THREAD compiler option

An ALTER statement referring to the paragraph that contains the altered GO TO statement should be executed before the GO TO statement is executed. Otherwise, the GO TO statement acts like a CONTINUE statement.

Read syntax diagramSkip visual syntax diagram
Format 3: altered GO TO statement

>>-paragraph-name--.--GO--+----+--.----------------------------><
                          '-TO-'      

When an ALTER statement refers to a paragraph, the paragraph can consist only of the paragraph-name followed by an unconditional or altered GO TO statement.

MORE-LABELS GO TO

The GO TO MORE-LABELS statement can be specified only in a LABEL declarative.

Read syntax diagramSkip visual syntax diagram
Format 4: MORE-LABELS GO TO statement

>>-GO--+----+--MORE-LABELS-------------------------------------><
       '-TO-'                

For more details, see Using trailer and header labels in the Enterprise COBOL Programming Guide.



Rate this page

[ Index | Table of contents ]