IF and END-IF in COBOL
A sailing call in a nested IF: no braces, just END-IF closing each block.
IDENTIFICATION DIVISION.
PROGRAM-ID. IF-ELSE.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WIND-KNOTS PIC 99 VALUE 26.
PROCEDURE DIVISION.
*> END-IF closes the block; no braces anywhere in the language.
IF WIND-KNOTS > 33
DISPLAY "Gale: stay in harbor"
ELSE
IF WIND-KNOTS > 21
DISPLAY "Reef the main and go"
ELSE
DISPLAY "Fair wind, full sail"
END-IF
END-IF
STOP RUN.
How it works
- The outer
IF WIND-KNOTS > 33catches gale force first. - The
ELSEarm nests a secondIFfor the reefing decision. - Each block ends with its own
END-IF, and the sentence ends with the period.
Keywords and builtins used here
DATADISPLAYDIVISIONELSEIDENTIFICATIONIFPROCEDURESECTIONSTOP
The run, in numbers
- Lines
- 17
- Characters to type
- 366
- Tokens
- 44
- Three-star pace
- 45 tpm
At the three-star pace of 45 tokens a minute, this run takes about 59 seconds.
Step 1 of 3 in Conditions, step 13 of 27 in Language basics.