Skip to content

GO TO Statement

The GO TO statement transfers controls to a named paragraph or section in the Procedure Division.

Format 1

GO TO procedure-name

Format 2

GO TO { proc-1 } ... DEPENDING ON numeric-data-1

Syntax:

  1. proc-n is the name of a procedure or section in the program.
  2. numeric-data-n is a numeric data item.

General Rules:

  1. The Format 1 GOTO statement transfers control to the named paragraph or section. If a section is named, control is transferred to the first paragraph in the section.
  2. In a Format 2 GOTO {list of paragraphs} DEPENDING statement, a list of paragraphs is followed by a numeric data item. The ordinal position of the paragraph in the list must correspond with the value of numeric-data-1 in order for it to be selected as the target of the GOTO statement. In the Code Sample below, the GOTO statement is followed by two procedure names, but since the GOTO-DEP-VAR is set to 1, the GOTO statement will transfer control to the first one.
  3. If the value of numeric-data-1 is less than 1 or greater than the number of listed GOTO targets, the operation is not executed, and control passes to the next statement.

Code Sample:

       IDENTIFICATION DIVISION. 
       PROGRAM-ID. GOTO-1. 
       ENVIRONMENT DIVISION. 
       DATA DIVISION. 
       WORKING-STORAGE SECTION. 
       77 GOTO-FLAG PIC 9 VALUE 1. 
       77 GOTO-DEP-VAR PIC 9 VALUE 1. 
       77 DUMMY PIC X. 
       PROCEDURE DIVISION. 
       MAIN. 
      *       GO TO PROCEDURE-NAME 
              IF GOTO-FLAG = 1 
                     GOTO GOTO-1-EXIT 
              END-IF. 

      *       GO TO { PROCEDURE-NAME } ... DEPENDING ON IDENTIFIER 
              GOTO DEP-1-EXIT, DEP-2-EXIT DEPENDING ON GOTO-DEP-VAR. 
       77 GOTO-DEP-VAR PIC 9 VALUE 1. 
       77 DUMMY PIC X. 
       PROCEDURE DIVISION. 
       MAIN. 
      *       GO TO PROCEDURE-NAME 
              IF GOTO-FLAG = 1 
                     GOTO GOTO-1-EXIT 
              END-IF. 

      *       GO TO { PROCEDURE-NAME } ... DEPENDING ON IDENTIFIER 
              GOTO DEP-1-EXIT, DEP-2-EXIT DEPENDING ON GOTO-DEP-VAR. 

       GOTO-1-EXIT. 
              DISPLAY "GOTO-1 EXIT!" LINE 10 COL 10. 
              ACCEPT DUMMY LINE 10 COL 30. 
              STOP RUN. 
       DEP-1-EXIT. 
              DISPLAY "DEP-1 EXIT!" LINE 10 COL 10. 
              ACCEPT DUMMY LINE 10 COL 30. 
              STOP RUN. 
       DEP-2-EXIT. 
              DISPLAY "DEP-2 EXIT!" LINE 10 COL 10. 
              ACCEPT DUMMY LINE 10 COL 30. 
              STOP RUN.
Back to top