The IF Statement and Scope Terminators
COBOL's IF statement evaluates a condition and executes the statements following it when true, optionally followed by an ELSE clause for the false path. Modern COBOL requires an explicit END-IF scope terminator when the IF is nested inside another conditional or when the statement block contains a period-sensitive ambiguity, replacing the older style of relying on a period to end the whole statement. Conditions can be simple relation tests like WS-AGE >= 18, class tests like WS-FIELD IS NUMERIC, or sign tests like WS-BALANCE IS NEGATIVE, and any of these can be combined with AND, OR, and NOT to form compound conditions.
Cricket analogy: IF WS-RUNS >= 100 DISPLAY "CENTURY" END-IF mirrors an umpire's rule check that triggers a milestone announcement only when a batter like Rohit Sharma crosses the century mark, with ELSE covering every other score.
Nested IF and Compound Conditions
Nested IF statements let a program branch on multiple related conditions, but deep nesting quickly becomes hard to read and is a common source of bugs when a misplaced END-IF changes which ELSE binds to which IF. Compound conditions built with AND, OR, and NOT follow standard logical precedence where NOT binds tightest, then AND, then OR, so complex conditions should use parentheses explicitly rather than relying on memorized precedence rules. A well-known COBOL shorthand also lets you write WS-STATUS = "A" OR "B" OR "C" as an abbreviated compound relation condition, which the compiler expands to three full comparisons against WS-STATUS.
Cricket analogy: IF WS-OVERS < 20 AND WS-WICKETS < 5 DISPLAY "ATTACK" END-IF mirrors a T20 captain's decision logic, combining overs remaining and wickets in hand before deciding to keep batters attacking, much like a death-overs strategy call.
PROCEDURE DIVISION.
IF WS-ACCOUNT-STATUS = "A"
IF WS-BALANCE >= WS-WITHDRAWAL-AMT
SUBTRACT WS-WITHDRAWAL-AMT FROM WS-BALANCE
DISPLAY "WITHDRAWAL APPROVED"
ELSE
DISPLAY "INSUFFICIENT FUNDS"
END-IF
ELSE
DISPLAY "ACCOUNT NOT ACTIVE"
END-IF.The EVALUATE Statement
EVALUATE is COBOL's multi-branch conditional, roughly equivalent to a switch/case construct in other languages but considerably more flexible because each WHEN clause can test a different condition, a range with THRU, or even multiple subjects at once using EVALUATE TRUE with independent condition-names. Unlike a chain of nested IFs, EVALUATE clearly separates each branch and evaluates WHEN clauses in order, stopping at the first match, with WHEN OTHER catching any case not explicitly handled. EVALUATE TRUE is an especially common idiom because it lets each WHEN contain a full independent condition rather than being restricted to comparing a single subject.
Cricket analogy: EVALUATE WS-RUNS WHEN 0 THRU 49 DISPLAY "START" WHEN 50 THRU 99 DISPLAY "HALF-CENTURY" WHEN OTHER DISPLAY "CENTURY-PLUS" mirrors how commentary graphics bucket a batter's innings into milestone ranges as the scoreboard updates.
PROCEDURE DIVISION.
EVALUATE TRUE
WHEN WS-ORDER-TOTAL > 1000
MOVE 0.15 TO WS-DISCOUNT-RATE
WHEN WS-ORDER-TOTAL > 500
MOVE 0.10 TO WS-DISCOUNT-RATE
WHEN WS-ORDER-TOTAL > 100
MOVE 0.05 TO WS-DISCOUNT-RATE
WHEN OTHER
MOVE 0 TO WS-DISCOUNT-RATE
END-EVALUATE.Condition-Names (88-Levels)
An 88-level condition-name attaches a readable boolean name to one or more specific values of its parent field, letting you write IF WS-VALID-STATUS instead of IF WS-STATUS = "A" OR WS-STATUS = "P", which makes business rules self-documenting and centralizes the valid values in one place in the DATA DIVISION. Setting a condition-name true with SET WS-VALID-STATUS TO TRUE moves the first listed value into the parent field, which is a convenient shorthand when there is exactly one value to set but ambiguous when a condition-name covers a range or list of values. Condition-names are one of COBOL's most effective readability tools because they let procedural logic read like plain business English while keeping the underlying literal values maintainable in a single declaration.
Cricket analogy: 88 WS-IS-OUT VALUES "B" "C" "LBW" "RO" lets code read IF WS-IS-OUT instead of comparing dismissal codes individually, similar to how a scoring app groups bowled, caught, LBW, and run-out under one 'dismissed' status.
Condition-names are declared as level 88 items subordinate to the field they describe, and they never occupy their own storage; they simply attach a name to a VALUE or VALUES THRU range of the parent field. This makes them free from a performance standpoint and highly valuable for maintainability, since changing which literal values represent a business condition only requires editing the 88-level clause.
- IF/ELSE requires an explicit END-IF scope terminator in nested or ambiguous contexts in modern COBOL.
- Compound conditions with AND, OR, and NOT follow standard precedence (NOT, then AND, then OR); use parentheses for clarity.
- COBOL supports abbreviated compound relation conditions like WS-STATUS = "A" OR "B" OR "C".
- EVALUATE is COBOL's multi-branch statement, supporting ranges with THRU and multi-condition testing via EVALUATE TRUE.
- WHEN OTHER in EVALUATE catches any case not explicitly matched, similar to a default branch.
- 88-level condition-names attach readable boolean names to specific values or ranges of a parent field.
- SET condition-name TO TRUE moves the first listed value of that condition-name into its parent field.
Practice what you learned
1. When is an explicit END-IF scope terminator required in modern COBOL?
2. In the compound condition NOT A AND B OR C, what is the evaluation order by standard COBOL precedence?
3. What advantage does EVALUATE TRUE offer over a standard EVALUATE on a single subject?
4. What does an 88-level condition-name represent in the DATA DIVISION?
5. What does SET WS-VALID-STATUS TO TRUE do if WS-VALID-STATUS is defined with multiple VALUES?
Was this page helpful?
You May Also Like
MOVE and Arithmetic Statements
Learn how COBOL's MOVE statement reformats data between fields and how ADD, SUBTRACT, MULTIPLY, DIVIDE, and COMPUTE perform arithmetic with proper rounding and overflow handling.
PERFORM Statement Variations
Explore the many forms of COBOL's PERFORM statement, from simple out-of-line calls and PERFORM THRU to TIMES, UNTIL, and in-line PERFORM blocks.
Loops in COBOL
See how COBOL's PERFORM statement is used in practice to build counting loops, nested loops, sentinel-controlled read loops, and how to exit them safely.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics