GO TO & Structured Programming

GO TO transfers control permanently (no return).

16.1 GO TO

GO TO transfers control permanently (no return). GO TO ... DEPENDING ON is a computed jump (value 1 → first label, etc.).

GO TO 9999-ABEND
           GO TO 100-ADD 200-CHANGE 300-DELETE
               DEPENDING ON WS-TRANS-CODE

16.2 Why to avoid it

Creates "spaghetti code" where control flow can't be understood locally.

Combined with PERFORM ... THRU, a GO TO outside the range breaks the return mechanism and causes control to "fall through" unpredictably.

ALTER (which changed a GO TO target at run time) was removed from the standard — if you meet it in legacy code, refactor it.

16.3 Acceptable uses (by convention)

Many shop standards allow exactly one pattern: GO TO paragraph-EXIT within a PERFORM ... THRU ... -EXIT range, and GO TO an abend routine. With COBOL-85+ scope terminators, EVALUATE, EXIT PERFORM, and EXIT PARAGRAPH, even those are unnecessary.

16.4 Structured design

Organize programs top-down: 0000-MAINLINE performs 1000-INITIALIZE (open files, read control card, priming read), then 2000-PROCESS until end of file (which performs 2100-VALIDATE, 2200-CALCULATE, 2300-WRITE-OUTPUT, 2900-READ-NEXT), then 9000-TERMINATE (totals, close files, set RETURN-CODE). One entry, one exit per paragraph; each paragraph does one job and fits on a screen.