Note: the end instruction is not a true Rexx instruction. It is described here as though it is an instruction for the reader's convenience only.
|end [ loopControlVariableName ]|
An end instruction concludes one of the following instruction groups:
A loopControlVariableName can be specified with the end instruction, only when it concludes a a counted do instruction group that has a named control variable. This name is compared versus all active counted loop control variables. The comparison of these names is performed independent of character case.
A name is not permitted with the end instruction, when it concludes a simple do instruction group. Nor is a name permitted with the end instruction, when it concludes a select instruction group.
When multiple do or select instruction groups are pending, the end instruction binds to the nearest incomplete instruction group. You cannot visually determine the associated instruction group of the end instruction, based on the instruction's indentation. Consider the following example:
do i=1 to 7 select when i=1 then say 'one' when i=2 then say 'a couple' otherwise if i < 6 then say 'a few' else do say 'more than a few' end /* this binds with the do after the else */ end /* this binds with the select group */ end /* this binds with the do group */
When multiple iterative do groups are pending, and each of these has a named control variable, then you should specify a name after each of the corresponding end instructions. If an inaccurate control variable is referenced, error 10 (unexpected or unmatched end is raised). For example:
do i=1 to 7 do j=1 to 7 do k=1 to 7 say i '*' j '*' k 'is:' i * j * k end kk /* <-- ERROR ! this should be a k */ end j end i