The IF statement provides for conditional action by the program.
General Format
IF condition THEN { {statement-1} }
{ NEXT SENTENCE }
[ ELSE {statement-2 } [END-IF] ]
[ ELSE NEXT SENTENCE ]
[ END-IF ]
Syntax Rules
- statement-1 and
statement-2 are imperative or conditional statements. An imperative statement can precede a conditional statement.
- condition is any conditional expression.
- The ELSE NEXT SENTENCE phrase is optional if it immediately precedes a period ending a sentence.
- If END-IF is specified, NEXT SENTENCE must not be specified.
General Rules
- The IF statement provides a method for selecting alternate sets of statements to execute depending on the truth value of condition.
- The scope of an IF statement ends when one of the following is encountered:
- A period ending a sentence.
- An END-IF phrase at the same nesting level.
- An ELSE phrase associated with an IF statement at a higher nesting level.
- If condition is
true, then
statement-1 executes.
statement-2 is not executed. If NEXT SENTENCE is used instead of
statement-1, control immediately passes to the next executable sentence. Note that the ANSI standard states that "NEXT SENTENCE is an
archaic feature and its use should be avoided."
- If condition is
false,
statement-2 executes.
statement-1 is not executed. If the ELSE NEXT SENTENCE phrase is used, control immediately passes to the next executable sentence. If
the ELSE phrase is not present, then control passes to the end of the IF statement.
- OTHERWISE is a synonym for ELSE in the IBM DOS/VS COBOL
-Cv compatibility mode. See IBM DOS/VS COBOL Conversions in
Transitioning to ACUCOBOL-GT for more information.