The GO TO Statement

The GO TO statement causes control to be transferred from one part of the Procedure Division to another.

The option of omitting procedure-name-1 in a Format 1 GO TO statement is classed as an obsolete element in the ANSI'85 standard and is scheduled to be deleted from the next full revision of the ANSI Standard.

All dialects in this COBOL implementation fully support this syntax. The FLAGSTD Compiler directive can be used to detect all occurrences of this syntax.

Although it is a part of the standard COBOL definition, omitting the procedure-name in Format 1 is explicitly excluded from the X/Open COBOL language definitions and should not be used in an X/Open COBOL conforming source program.

General Formats for Format 1


GO TO - Format 1

General Formats for Format 2


GO TO - Format 2

Syntax Rules for All Formats

  1. Identifier is the name of a numeric elementary item which is an integer.
  2. When a paragraph is referenced by an ALTER statement, that paragraph can consist only of a paragraph header followed by a Format 1 GO TO statement.

Syntax Rules for Format 1

  1. A Format 1 GO TO statement, without procedure-name-1, can only appear in a single statement paragraph.

    This restriction is not enforced.

  2. If a Format 1 GO TO statement appears in a consecutive sequence of imperative statements within a sentence, it must appear as the last statement in that sequence.

Syntax Rules for Format 2

  1. In Format 2, at least two procedure-names should be specified.

    A Format 2 statement can be written with only one procedure name.

General Rules for All Formats

  1. If procedure-name-1 is not specified in Format 1, an ALTER statement, referring to this GO TO statement, must be executed prior to the execution of this GO TO statement.

    If an ALTER statement referring to the paragraph containing this GO TO statement has not been executed before this GO TO statement is executed, this GO TO statement is treated like a CONTINUE statement.

General Rules for Format 1

  1. When a GO TO statement represented by Format 1 is executed, control is transferred to procedure-name-1 or to another procedure-name if the GO TO statement has been modified by an ALTER statement.

General Rules for Format 2

  1. When a GO TO statement represented by Format 2 is executed, control is transferred to procedure-name-1, procedure-name-2, and so on, depending on the value of the identifier being 1, 2, ..., n. If the value of the identifier is anything other than the positive or unsigned integers 1, 2, ..., n, then no transfer occurs and control passes to the next statement in the normal sequence for execution.