COBOL Manual for TNS and TNS/R Programs

Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs522555-006
9-84
Delimited-Scope Form
ELSE
ends statement-1.
statement-2
is an imperative or conditional statement to be executed if the value of condition
is FALSE. It can contain other IF statements.
END-IF
ends the scope of the IF statement, making it a delimited-scope statement. Without
END-IF, the IF statement is a conditional statement that ends at the next period
separator.
Usage Considerations:
Delimited-Scope Statements Are Recommended Over Conditional Statements
For clarity and convenience, delimited-scope statements are recommended over
conditional statements.
Period Separator in Delimited-Scope IF Statement
A delimited-scope IF statement does not require a period separator. If a period
separator occurs within a delimited-scope IF statement, it terminates the statement
and the compiler diagnoses the END-IF as unmatched.
Nested Delimited-Scope IF Statements
Delimited-scope IF statements can be “nested” (included) within other delimited-
scope IF statements. Nested delimited-scope IF statements are interpreted by
pairing each IF phrase with an ELSE phrase, ELSE … END-IF pair, or isolated
END-IF phrase, proceeding from left to right within a sentence. Each ELSE, ELSE
… END-IF, or isolated END-IF that the compiler encounters is considered to
correspond to the nearest previous IF phrase that has not already been paired with
an ELSE, ELSE … END-IF, or isolated END-IF.
How the Delimited-Scope IF Statement Works
The condition is evaluated. If its value is TRUE, statement-1 is executed. If
control reaches the point immediately following statement-1 (that is,
statement-1 completes without executing a GO TO statement or the
equivalent), control passes to the end of the IF statement. The ELSE phrase, if
present, is ignored.
If the value of condition is FALSE and an ELSE phrase is present,
statement-2 is executed. If control reaches the point immediately following
statement-2 (that is, statement-2 completes without executing a GO TO
statement or the equivalent), control passes to the end of the IF statement.
If the value of condition is FALSE and there is no ELSE phrase, control passes
to the end of the IF statement.