END

Purpose

Terminates a block or group headed by the most recent DO, PROCEDURE, SELECT, or BEGIN statement.

Syntax

END [statement_label];

Parameters

statement_label
The label prefix of the corresponding statement.

Description

The END statement terminates a block or group headed by the most recent DO, PROCEDURE, SELECT, or BEGIN statement.

Execution of an END statement that closes a DO-group may cause the group to be repeated, depending on the DO statement that heads the group. (Refer to previous sections of this chapter regarding DO statements.)

Execution of an END statement that closes a PROCEDURE statement is valid only if the PROCEDURE statement does not contain a RETURNS option. Open PL/I or another implementation of PL/I might not diagnose all violations of this requirement. The END statement ends the current block activation and returns control to the statement following the CALL statement that called the procedure.

Execution of an END statement that closes a BEGIN block ends the current block activation and resumes execution of the previous block activation with the statement following the END statement. If the BEGIN block is an ON-unit, control returns to the source of the signal. This return is not possible if the ON-unit has been established for the ERROR condition; an attempt to return to the source of the ERROR condition stops execution of the program and produces a run-time error message.

An END statement can have a label prefix and can be referenced by a GOTO statement, including GOTO statements contained within the DO-group or block that is closed by the END statement.

If a name is given, it must be the same name as occurs in the label prefix of the corresponding DO, BEGIN, or PROCEDURE statement. If the name is not the same, the Compiler issues an error message.

An END statement cannot appear as a THEN, ELSE, WHEN, or OTHERWISE clause or as an ON-unit.

Example

P: PROCEDURE;
   DO K=1 TO 10;
      .
      .
      .
   END;
   END P;

If control passes to an END statement that implicitly closes a repetitive DO group, no further repetitions of the DO group occur. It is equivalent to a branch out of the DO group.

Restrictions

None.