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

IF WS-BALANCE > 0 DISPLAY "ACCOUNT IN CREDIT" ELSE DISPLAY "ACCOUNT NOT IN CREDIT" END-IF.

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:

05 WS-ACCOUNT-STATUS PIC X(1). 88 WS-STATUS-ACTIVE VALUE "A". 88 WS-STATUS-CLOSED VALUE "C".

a real condition name can be tested directly, instead of comparing the underlying field to a literal:

IF WS-STATUS-ACTIVE DISPLAY "PROCESSING ACTIVE ACCOUNT" END-IF.
Why This Is Genuinely Worth Using 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.

EVALUATE WS-ACCOUNT-STATUS WHEN "A" DISPLAY "ACTIVE" WHEN "C" DISPLAY "CLOSED" WHEN OTHER DISPLAY "UNKNOWN STATUS" END-EVALUATE.

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:

PERFORM PARA-VALIDATE.

A real THRU form executes a whole sequence of adjacent paragraphs, in order:

PERFORM PARA-A THRU PARA-C.

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 UNTIL WS-EOF-FLAG = "Y" DISPLAY "PROCESSING..." MOVE "Y" TO WS-EOF-FLAG END-PERFORM.

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 VARYING WS-I FROM 1 BY 1 UNTIL WS-I > 10 DISPLAY WS-I END-PERFORM.

PERFORM ... TIMES repeats a fixed real number of times instead of testing a condition:

PERFORM 5 TIMES DISPLAY "HELLO" END-PERFORM.
A Real, Documented Limit The TIMES phrase can genuinely repeat up to 999,999,999 times — a real, documented ceiling, not an arbitrary round number, worth knowing exists even though almost no real program ever approaches it.

Hands-On Exercises

Exercise 1

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.

📄 View solution
Exercise 2

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 solution
Exercise 3

Rewrite 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 solution

Chapter 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 OTHER catch-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