2.6 Block Labels and continue Blocks
We have seen the use of labels on loops already in this chapter. In general, a label can be placed before any loop statement. This means that a label can be placed before while, until, for and foreach statements. A label can also be placed before a bare block. Thus, the following are acceptable.
LABEL: while ( expression ) block
LABEL: while ( expression ) block continue block
LABEL: until ( expression ) block
LABEL: until ( expression ) block continue block
LABEL: for ( initialization ; termination-condition ; update ; ) block
LABEL: foreach variable ( list ) block
LABEL: foreach variable ( list ) block continue block
LABEL: block
LABEL: block continue block
This list is taken from [WCS96]. Labels are not allowed with if or unless statements. A label is a string of alphanumeric characters. A label needs to be followed by a colon. It is customary, but not required to write the label in all upper case letters so that it stands out from among the rest of the code. A label is usually used to allow ways to control how the block associated with a loop statement is executed. Loop control statements: next, last and redo can use loop labels. A label names the loop as a whole and not just the top of the loop. Thus, a loop control command referring to a loop’s label works with respect to the loop as a whole.
We see that only some of the loop statements allow one to use the continue block. The continue block if used, provides the bridge to continue from one iteration to the next unless skipped explicitly. The continue block is not executed the last time. The block is optional. last makes a program skip the continue block. The redo command skips the continue block. The redo command skips condition testing for the next iteration as well. The next command causes the continue block to be executed. The next command requires the conditional to be tested before the next iteration.
