typestar

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

  1. The outer IF WIND-KNOTS > 33 catches gale force first.
  2. The ELSE arm nests a second IF for the reefing decision.
  3. Each block ends with its own END-IF, and the sentence ends with the period.

Keywords and builtins used here

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.

Type this snippet

Step 1 of 3 in Conditions, step 13 of 27 in Language basics.

← Previous Next →