Parallel with IF in other languages; types:
1-branch (IF/END-IF)
2-branch (IF/ELSE/END-IF)
The conditional statement is always written with block formula. There is no inline version. The closing END-IF is optional in 1-branch conditionals.
EXAMPLE FOR SYNTAX OF IF CONDITIONALS:
EXAMPLE FOR IF CONDITIONALS:
COBOL version of CASE/SWITCH multiple choices selector which creates more execution branches based on values of a given expression.
The EVALUATE header contains a testable expression made of iterals and variables (representing literals). Usually variables are tested.
The branches begin with WHEN, and the given branch contains a value or values responding to the testable expression in the header; if the value(s) match(es), the flow will enter into the branch.
The branch values should render every WHEN branch distinct from other WHENs but it is not obligatory. In case the execution flow could enter into multiple branches, it will continue in the first one.
The OTHER marks a choice not presented by any WHENs (ELSE branch); optional.
In case a branch contains one statement only, that line can be written together with the line of the WHEN (compressed branch).
The EVALUATE is able to check more expressions as well (multi-argument selector). In such case, the ALSO word separates the testable expressions in the selector head, and the ALSO separates the conditions for the expressions, in the order of expressions in the head. After the 5-6th expressions the code will be not readable. The conditions can mix literals, variables (representing literals), and intervals.
In case we want to accept every possible value for an argument, use the ANY keyword for the corresponding exression.
The EVALUATE can work as a multi-branch IF conditional statement in case the expression is TRUE. Here, the WHENs will contain full conditions. Within this type, the multi-branch, single-argument selector is used most of the time in modern COBOL.
An interval means all values between the given limits, limits are included, e.g. the mathematical interval [a, b] is "a" THRU "b" in COBOL. The data type can be numeric, alphabetic or alphanumeric, COBOL uses lexicographic ordering (ABC).
Using the CONTINUE command makes COBOL to exit from the selector.
EXAMPLE FOR INTERVAL:
EXAMPLE FOR SYNTAX OF EVALUATE:
EXAMPLE FOR EVALUATE:
The EVALUATE can work together with level-88 condition-names where the WHEN values are condition-names. The selector must be multi-branch.
See the CONDITION-NAMES (LEVEL 88) section.
EXAMPLE FOR EVALUATE WITH LEVEL-88:
Logical aliases for field values.
EXAMPLE FOR CONDITION-NAMES:
To test against contained data type:
NUMERIC (all characters are 0..9)
ALPHABETIC (all characters are A..Z, a..z)
ALPHANUMERIC (all characters are letters or numbers)
LOWER
UPPER
EXAMPLE FOR CLASS CONDITIONS:
Test against position on the numeric spectrum:
POSITIVE
NEGATIVE
ZERO
EXAMPLE FOR SIGN CONDITIONS:
Used in file operations.
EXAMPLE FOR FILE I/O CONDITIONS: