The IF statement evaluates a condition and provides for alternative actions in the object program, depending on the evaluation.
Format .-------------. V | >>-IF--condition-1--+------+--+---statement-1-+-+---------------> '-THEN-' '-NEXT SENTENCE---' >--+---------------------------+--+------------+--------------->< | .-------------. | | (1) | | V | | '-END-IF-----' '-ELSE--+---statement-2-+-+-' '-NEXT SENTENCE---'
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.
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:
If the condition tested is true, one of the following actions takes place:
If the condition tested is false, one of the following actions takes place:
When the ELSE phrase is omitted, all statements following the condition and preceding the corresponding END-IF or the separator period for the sentence are considered to be part of statement-1.
When an IF statement appears as statement-1 or statement-2, or as part of statement-1 or statement-2, that IF statement is nested.
Nested IF statements are considered to be matched IF, ELSE, and END-IF combinations proceeding from left to right. Thus, any ELSE encountered is matched with the nearest preceding IF that either has not been already matched with an ELSE or has not been implicitly or explicitly terminated. Any END-IF encountered is matched with the nearest preceding IF that has not been implicitly or explicitly terminated.