Control Flow: IF, EVALUATE & PERFORM
COBOL Fundamentals
Chapter 5 · Control Flow: IF, EVALUATE & PERFORM
Chapter 3 introduced 88-level condition names and deferred their real use to this chapter. This chapter delivers on that — real IF logic, COBOL's own switch-equivalent EVALUATE, and every real form PERFORM takes, from a single subroutine call to a full counted loop.
IF Statements
Real, ordinary relation conditions (>, <, =, and their combinations) work exactly as expected, closed with the real END-IF scope terminator.
Condition Names (88-Levels), Finally Put to Use
Recall Chapter 3's own real 88-level condition names. Given a declaration like:
a real condition name can be tested directly, instead of comparing the underlying field to a literal:
IF WS-STATUS-ACTIVE and IF WS-ACCOUNT-STATUS = "A" do exactly the same real thing — but the condition-name version reads as a genuine business concept ("is this account active?") rather than a raw literal comparison, and if the underlying stored code for "active" ever changed, only the 88-level's own VALUE clause needs updating, not every IF statement that checks it throughout a real program.
EVALUATE: COBOL's Real Switch Equivalent
Introduced in COBOL-85, EVALUATE is COBOL's real answer to a switch/case statement — and genuinely more flexible than IF/ELSE chains for handling several possible values.
WHEN OTHER is the real catch-all, matching anything not covered by an earlier WHEN. EVALUATE can also test genuine TRUE/FALSE conditions rather than only literal values — real, direct condition testing, not just value matching.
PERFORM: Simple Invocation & THRU
The simplest real form of PERFORM invokes one named paragraph and returns:
A real THRU form executes a whole sequence of adjacent paragraphs, in order:
PERFORM UNTIL & Inline PERFORM
PERFORM ... UNTIL is COBOL's real conditional loop, and — also introduced in COBOL-85 — an inline PERFORM lets the loop body sit directly inside the statement itself, closed with END-PERFORM, with no separate paragraph needed:
PERFORM VARYING & PERFORM TIMES
PERFORM VARYING is COBOL's real counted loop — the closest equivalent to a for-loop in more modern languages — automatically increasing or decreasing an index each pass:
PERFORM ... TIMES repeats a fixed real number of times instead of testing a condition:
Hands-On Exercises
Using this chapter's own real 88-level example, explain in your own words why IF WS-STATUS-ACTIVE is genuinely preferable to IF WS-ACCOUNT-STATUS = "A", beyond simply being shorter to type.
A colleague says, "PERFORM UNTIL and PERFORM VARYING do the same job — they're both loops." Using this chapter's own real material, explain in your own words the specific real difference between them, and when you'd genuinely choose one over the other.
📄 View solutionRewrite this chapter's own real EVALUATE example (testing WS-ACCOUNT-STATUS for "A" and "C") as an equivalent IF/ELSE IF chain. Explain, in your own words, one genuine real advantage EVALUATE has over the IF/ELSE IF version once a third or fourth status code needs handling.
📄 View solutionChapter 5 Quick Reference
- IF/ELSE/END-IF — real relation conditions; 88-level condition names can be tested directly (e.g.
IF WS-STATUS-ACTIVE) - EVALUATE (COBOL-85) — real switch equivalent;
WHEN OTHERcatch-all; can test TRUE/FALSE conditions, not just values - PERFORM paragraph / PERFORM a THRU b — real subroutine-style invocation
- PERFORM UNTIL / inline PERFORM (COBOL-85) — real conditional loop
- PERFORM VARYING ... FROM ... BY ... UNTIL — real counted loop; PERFORM n TIMES — real fixed repetition, up to 999,999,999