IF statement

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

Format

Read syntax diagramSkip visual syntax diagramIFcondition-1THENstatement-1NEXT SENTENCEELSEstatement-2NEXT SENTENCEEND-IF1
Notes:
  • 1 END-IF can be specified with statement-2 or NEXT SENTENCE.

condition-1
Can be any simple or complex condition, as described in Conditional expressions.
statement-1, statement-2
Can be any one of the following options:
  • An imperative statement
  • A conditional statement
  • An imperative statement followed by a conditional statement
NEXT SENTENCE
The NEXT SENTENCE phrase transfers control to an implicit CONTINUE statement immediately following the next separator period.

When NEXT SENTENCE is specified with END-IF, control does not pass to the statement following the END-IF. Instead, control passes to the statement after the closest following period.

END-IF phrase

This explicit scope terminator serves to delimit the scope of the IF statement. END-IF permits a conditional IF statement to be nested in another conditional statement. For more information about explicit scope terminators, see Delimited scope statements.

The scope of an IF statement can be terminated by any of the following options:

  • An END-IF phrase at the same level of nesting
  • A separator period
  • If nested, by an ELSE phrase associated with an IF statement at a higher level of nesting