In addition to the standard set of iterative do looping capabilities, Rexx also has two additional loop refinements -- the iterate and leave instructions.
iterate [ loopControlVariableName ] |
An iterate instruction causes the associated loop to proceed with its next cycle, as though the corresponding end instruction had been encountered. A loopControlVariableName can be specified with the iterate instruction, only when a counted do instruction group has the 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. When a A loopControlVariableName is specified, the next iteration of the associated loop ensues. When a loopControlVariableName is absent, the next iteration of the innermost active loop ensues.
Two examples are provided below. The first shows every other line in the input stream. The second is more eccentric.
/* this program shows every other line in the input stream */ do lineNumber=1 while lines( ) > 0 lin = linein( ) if lineNumber // 2 = 0 then iterate /* skip this line */ say lin end |
leave [ loopControlVariableName ] |
An leave instruction concludes its associated loop. Execution continues with the instruction that follows the end instruction of the associated loop. A loopControlVariableName can be specified with the leave instruction, only when a counted do instruction group has the 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. When a A loopControlVariableName is specified, that do instruction group is concluded. When a loopControlVariableName is absent, the innermost active loop is concluded.
Two examples are provided below. The first locates an excessively long line in the input stream. The second is more eccentric.
/* this program searches for an excessive line in the input stream */ do while lines( ) > 0 lin = linein( ) if length( lin ) > 80 then do say 'The following line is too long' say ' lineNumber'.' lin leave /* conclude line processing */ end end |