IF Statement

The IF statement evaluates a condition and provides for alternative actions in the object program, depending on the evaluation.

Read syntax diagramSkip visual syntax diagram
IF Statement — Format

>>-IF--condition--+------+-------------------------------------->
                  '-THEN-'   

       .-----------------.                                              
       V                 |                                              
>--+-+-----statement-1---+-+--+-------------------------------+-----+-><
   | '-NEXT SENTENCE-------'  |         .-----------------.   |     |   
   |                          |         V                 |   |     |   
   |                          '-ELSE--+-----statement-2---+-+-'     |   
   |                                  '-NEXT SENTENCE-------'       |   
   | .-----------------.          .-----------------.               |   
   | V                 |          V                 |               |   
   '-----statement-1---+--+-ELSE------statement-2---+--+--------+-+-'   
                          |                            '-END-IF-' |     
                          '-END-IF--------------------------------'     

The scope of an IF statement can be terminated by any of the following:
Related Information:
condition
May be any simple or complex condition, as described in Conditional Expressions.
statement-1, statement-2
Can be any one of the following:
  • An imperative statement
  • A conditional statement
  • An imperative statement followed by a conditional statement
NEXT SENTENCE
If the END-IF phrase is specified, the NEXT SENTENCE phrase must not be specified.
IBM Extension

NEXT SENTENCE can be specified with END-IF.

End of IBM Extension
ELSE NEXT SENTENCE
May be omitted if it immediately precedes a separator period that ends the IF statement.