The EXIT-BLOCK command terminates the processing of the command sequence within the block and branches to the block termination command. Procedure execution is then resumed with the command that follows the block termination command.
The block that is to be terminated can be addressed in the EXIT-BLOCK command call either implicitly by the preset value *LAST or explicitly via the name of the tag that precedes a block initiation command.
Example
/LOOP: WHILE (COND < 9) /... /IF (INP='*END') / EXIT-BLOCK LOOP /END-IF /... /END-WHILE /”Following EXIT-BLOCK, procedure execution is resumed here”
When branching with EXIT-BLOCK, the tag specified can be either that of the current block (as in the example above) or that of a surrounding block.
Example
/LOOPWH: WHILE (COND<9) /... /LOOPFOR: FOR I=*LIST(LIST) /... / IF (COND=TRUE) /... / EXIT-BLOCK LOOPWH /... / END-IF /... / END-FOR /... /END-WHILE /”Execution resumes here after EXIT-BLOCK”
With the *ALL operand it is possible to terminate all surrounding blocks. Procedure execution is then resumed with the command following the END command that terminates the outside block on the highest procedure level. Using EXIT-BLOCK *ALL is practical, for example, in error handling blocks when the procedure is to be correctly terminated rather than resumed following an error.
Note
If /EXIT-BLOCK is written without a destination tag in an IF block, the procedure is continued after the associated END-IF.
The presetting BLOCK=*LAST should therefore not be used to address the block to be terminated unless the branch condition is specified in the EXIT-BLOCK command.