💻 COBOL
COBOL GO TO Statement
Beginner 🕑 10 min read
👁 0 views
COBOL GO TO Statement
The GO TO statement transfers control unconditionally to another paragraph or section.
Syntax
GO TO paragraph-name
GO TO paragraph-1 paragraph-2 ... DEPENDING ON identifier
Example Program
IDENTIFICATION DIVISION.
PROGRAM-ID. GOTO-DEMO.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-OPTION PIC 9 VALUE 2.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY 'Starting program...'
* GO TO DEPENDING ON
GO TO OPTION-1 OPTION-2 OPTION-3
DEPENDING ON WS-OPTION
GO TO END-PARA.
OPTION-1.
DISPLAY 'Option 1 selected'
GO TO END-PARA.
OPTION-2.
DISPLAY 'Option 2 selected'
GO TO END-PARA.
OPTION-3.
DISPLAY 'Option 3 selected'
GO TO END-PARA.
END-PARA.
DISPLAY 'Program ending...'
STOP RUN.
Expected Output
Starting program...
Option 2 selected
Program ending...
Key Points
- GO TO transfers control unconditionally
- GO TO DEPENDING ON provides multi-way branch
- Modern COBOL prefers PERFORM and EVALUATE
- Excessive GO TO creates "spaghetti code"
- Use sparingly for error handling or exits