IF Statement

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

  1. statement-1 and statement-2 are imperative or conditional statements. An imperative statement can precede a conditional statement.
  2. condition is any conditional expression.
  3. The ELSE NEXT SENTENCE phrase is optional if it immediately precedes a period ending a sentence.
  4. If END-IF is specified, NEXT SENTENCE must not be specified.

General Rules

  1. The IF statement provides a method for selecting alternate sets of statements to execute depending on the truth value of condition.
  2. The scope of an IF statement ends when one of the following is encountered:
    1. A period ending a sentence.
    2. An END-IF phrase at the same nesting level.
    3. An ELSE phrase associated with an IF statement at a higher nesting level.
  3. 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."
  4. 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.
  5. 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.