Limbo labels are somewhat like C goto
statements, except labels can only be used with break
and continue
statements in for
, while
and do
...while
loops, and in case
and alt
statements. This transfers control to the end of the enclosing block that is labelled.
There are two typical uses of labels in Limbo. One is to allow an inner loop to break
or continue
to an outer loop. Another is to break to an outer loop from within a case
or alt
statement.
Consider the following example. One or more options can be passed to a command and parsed:
loop: for(i := 0; i < len in; i++){ case in[i] { 'v' => opt |= Verbose; 's' => opt |= Suppress; 'o' => opt |= OutFile; * => break loop; } }As long as the
i
th element in the string in
is one of the valid options (v
, s
, or o
), procesing continues; the for
loop starts the next iteration. At the point that any other character is encountered, processing is termintated by the break loop
statement.
If the label is not used with the break
, the for
loop simply starts the next iteration.
The next example shows how the label can be used to break out of a multi-nested loop:
u := 0; line := "<A HREF=\"http://www.lucent.com/inferno\">" URL := ""; outer: for (i := 0; i < len line; i++) { if (line[i] == '<') { while (line[++i] != '>') { if (line[i:i+6] == "A HREF") { i += 6; if (line[i] == '=') { i += 2; while (line[i] != '"') URL[u++] = line[i++]; } } break outer; } } }