break
The break command leaves the innermost for or while loop at once.
Syntax
break
break takes no arguments and stands alone on its line.
What it does
When James reaches break on a pass, it stops repeating the loop for good. No later pass runs, and the rest of the body after the break on that pass is skipped. James reads on after the loop’s closer. break is usually wrapped in a when, because an if cannot sit in a loop.
When James applies it
By the preprocessor, when it is read. A break is resolved before the phase of the parser matters, so it is legal anywhere inside a loop.
Rules James adds
breakleaves the innermost loop, not every loop that holds it. In nestedforloops, abreakin the inner loop ends only the inner loop, and the outer loop goes on.breakstands alone on its line, like every control statement.- A
breakoutside aforor awhileis an error.
Diagnostics
Example
The script tests/corpus/163-break-leaves-for/input.tg, which make test runs:
c a for loop of ten passes that break leaves on the third
for i 1 10 1
para last %i;
when(%i.eq.3) then
break
endwhen
endfor
The for is set for ten passes. On the third, %i.eq.3 is true and the break ends the loop. The prep dump shows para last 1;, para last 2; and para last 3;, and nothing after.