Menu
CoddyTech

EVALUATE ALSO

Part of the Decisions and Loops section of Coddy's COBOL Programming journey. Lesson 10 of 20.

ALSO evaluates two subjects at once. Each WHEN gives one value per subject, and both must match:

EVALUATE CARD ALSO ONLINE
    WHEN "C" ALSO "Y"
        DISPLAY "Fee 2"
    WHEN "D" ALSO "Y"
        DISPLAY "Fee 1"
    WHEN ANY ALSO "N"
        DISPLAY "Fee 0"
END-EVALUATE.

ANY matches every value of its subject, so any card used in a shop (ONLINE is N) pays no fee.

Each WHEN is one row of a decision table, where business rules are written as columns of conditions.

Subjects can mix. EVALUATE TRUE ALSO MEMBER takes a condition in the first column and a value of MEMBER in the second:

WHEN TOTAL >= 100 ALSO ANY
WHEN ANY ALSO "Y"
challenge icon

Challenge

Easy

Read ZONE and EXPRESS. Print Shipping 5 for zone D without express, Shipping 15 for D with express (Y), Shipping 30 for zone I either way and Invalid zone otherwise.

Example input, one line per ACCEPT: D, N.

Try it yourself

       IDENTIFICATION DIVISION.
       PROGRAM-ID. SHIPPING.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 ZONE PIC X.
       01 EXPRESS PIC X.
       PROCEDURE DIVISION.
           ACCEPT ZONE.
           ACCEPT EXPRESS.
           *> EVALUATE ZONE ALSO EXPRESS here
           STOP RUN.
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Decisions and Loops