typestar

EVALUATE in COBOL

EVALUATE is COBOL's switch: one subject, a WHEN per cargo code, OTHER for the rest.

IDENTIFICATION DIVISION.
PROGRAM-ID. EVALUATE-WHEN.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CARGO-CODE  PIC X VALUE "G".
PROCEDURE DIVISION.
*> EVALUATE is the switch: WHEN takes values, ranges, or OTHER.
    EVALUATE CARGO-CODE
        WHEN "G" DISPLAY "General cargo: any hold"
        WHEN "R" DISPLAY "Reefer: plug it in"
        WHEN "H" DISPLAY "Hazmat: deck stowage only"
        WHEN OTHER DISPLAY "Unknown code, hold the manifest"
    END-EVALUATE
    STOP RUN.

How it works

  1. EVALUATE CARGO-CODE names the subject once.
  2. Each WHEN "G" arm pairs a value with its statement.
  3. WHEN OTHER catches unknown codes, and END-EVALUATE closes the scope.

Keywords and builtins used here

The run, in numbers

Lines
14
Characters to type
429
Tokens
45
Three-star pace
40 tpm

At the three-star pace of 40 tokens a minute, this run takes about 68 seconds.

Type this snippet

Step 2 of 3 in Conditions, step 14 of 27 in Language basics.

← Previous Next →