Coding a choice of actions
Use IF . . . ELSE to code a choice between
two processing actions. (The word THEN is optional.)
Use the EVALUATE statement to code a choice among
three or more possible actions.
About this task
IF condition-p
statement-1
ELSE
statement-2
END-IF
When
one of two processing choices is no action, code the IF statement
with or without ELSE. Because the ELSE clause
is optional, you can code the IF statement as follows:
IF condition-q
statement-1
END-IF
Such
coding is suitable for simple cases. For complex logic, you probably
need to use the ELSE clause. For example, suppose
you have nested IF statements in which there is an
action for only one of the processing choices. You could use the ELSE clause
and code the null branch of the IF statement with
the CONTINUE statement:
IF condition-q
statement-1
ELSE
CONTINUE
END-IF
NEXT SENTENCE can be very different
from CONTINUE, based on location of the following
period, as shown in this example:IF condition-r
statement-1
ELSE
CONTINUE or NEXT SENTENCE
END-IF
*> CONTINUE goes to statement-2
statement-2
statement-3.
*> NEXT SENTENCE goes to statement-4
statement-4For details about NEXT SENTENCE,
see IF
statement in the Enterprise COBOL for z/OS® Language Reference. The EVALUATE statement
is an expanded form of the IF statement that allows
you to avoid nesting IF statements, a common source
of logic errors and debugging problems.