IF command (COBOL)

The IF command lets you conditionally perform a command. You can optionally specify an ELSE clause on the IF command. If the test expression evaluates to false and an ELSE clause exists, the command associated with the ELSE clause is performed. The keywords cannot be abbreviated.

Read syntax diagramSkip visual syntax diagram
                            .---------.   
                            V         |   
>>-IF--condition--+------+----command-+------------------------->
                  '-THEN-'                

>--+-------------------+--END-IF--;----------------------------><
   |       .---------. |              
   |       V         | |              
   '-ELSE----command-+-'              

condition
A simple relation condition with the following form: Item-1 operator Item-2. Item-1 and Item-2 can be a data-item or a literal. The operator can be one of the following operations:
  • >
  • <
  • =
  • NOT =
  • >=
  • <=
  • NOT <
  • NOT >
command
A valid Debug Tool command.

When IF commands are nested and ELSE clauses are present, a given ELSE or END-IF is associated with the closest preceding IF clause within the same block.

Unlike COBOL, Debug Tool requires terminating punctuation (;) after commands. The END-IF keyword is required.

Usage notes

Refer to the following topics for more information related to the material discussed in this topic.