COBOL (IBM Mainframe)
ID DIVISION.
PROGRAM-ID. USELESS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 W-WHEN-COMPILED PIC X(8)BX(8) VALUE SPACE.
PROCEDURE DIVISION.
IF W-WHEN-COMPILED EQUAL TO SPACE
NEXT SENTENCE
END-IF
MOVE SPACE TO W-WHEN-COMPILED.
MOVE WHEN-COMPILED TO W-WHEN-COMPILED
DISPLAY W-WHEN-COMPILED " HELLO WORLD!"
GOBACK
.
If you run the above program (any IBM Mainframe COBOL since COBOL II (first IBM compiler to 1985 standard, probably other IBM COBOLs as well) the output is:
02/22/14 13.11.02 HELLO WORLD!
However, if you remove the triply-useless line "MOVE SPACE TO W-WHEN-COMPILED." (the field has an initial value of space, and has other content placed in it in the next instruction, and it is branched over anyway) the program produces no output and actually Abends (U4038) (that means it crashes) with the following message:
IGZ0037S The flow of control in program USELESS proceeded beyond the
last line of the program. From compile unit USELESS at entry
point USELESS at compile unit offset +000003AC at entry offset
+000003AC at address 119003AC.
(message code and text would vary amongst compilers, offsets depend upon actual compiler used and compile options, address depends on where program is loaded when EXECuted).
The reason is the NEXT SENTENCE
. This is a Secret GO TO
. The compiler hunts down the next full-stop/period in the source, and generates a branch to the following instruction. From COBOL II, the use of full-stops/periods was relaxed. A program must end with a full-stop/period. In this case, the branch is off the end of the program.
Both programs compile 100% clean (no diagnostic messages, Return Code of zero).
This behaviour is a dumb "IBM Extension" to COBOL. The 1985 Standard does not allow NEXT SENTENCE
within IF
/END-IF
(CONTINUE
is used instead, which is a no-op). IBM allowed it - causing horrible Gotchas from time-to-time.