A procedure is terminated when, by some means other than a procedure reference, control passes back to the invoking program, block, or to some other active block.
Procedures terminate normally when:
Procedures terminate abnormally when:
Transferring control out of a procedure using a GO TO statement can sometimes result in the termination of several procedures and/or begin-blocks. Specifically, if the transfer point specified by the GO TO statement is contained in a block that did not directly activate the block being terminated, all intervening blocks in the activation sequence are terminated. In the following example:
A: procedure options(main);
statement-1
statement-2
B: begin;
statement-b1
statement-b2
call C;
statement-b3
end B;
statement-3
statement-4
C: procedure;
statement-c1
statement-c2
statement-c3
D: begin;
statement-d1
statement-d2
go to Lab;
statement-d3
end D;
statement-c4
end C;
statement-5
Lab: statement-6
statement-7
end A;
A activates B, which activates C, which activates D. In D, the statement go to Lab transfers control to statement-6 in A. Since this statement is not contained in D, C, or B, all three blocks are terminated; A remains active. Thus, the transfer of control out of D results in the termination of intervening blocks B and C as well as the termination of block D.