The following program should print "ABBCDECDEF
" (replace STOP
with STOP RUN
and it will turn into a proper COBOL program which you can run to test this behaviour yourself):
* PERFORM + GO TO interplay example
IDENTIFICATION DIVISION.
PROGRAM-ID. PERFORM-GO-TO.
PROCEDURE DIVISION.
A.
DISPLAY "A" WITH NO ADVANCING.
* print B and come back
PERFORM B.
* print B and C and come back
PERFORM B THROUGH C.
* print D and E and come back, D will go to E but the execution will continue
PERFORM D THROUGH E.
* print C and D and then go to E which is outside the range
* so the execution will go to F and stop
PERFORM C THROUGH D.
* so we will never return here to execute the following statement
DISPLAY "A" WITH NO ADVANCING.
B.
DISPLAY "B" WITH NO ADVANCING.
C.
DISPLAY "C" WITH NO ADVANCING.
D.
DISPLAY "D" WITH NO ADVANCING.
GO TO E.
* the following statement is always dead code
DISPLAY "D" WITH NO ADVANCING.
E.
DISPLAY "E" WITH NO ADVANCING.
F.
DISPLAY "F" WITH NO ADVANCING.
STOP.