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

  • break leaves the innermost loop, not every loop that holds it. In nested for loops, a break in the inner loop ends only the inner loop, and the outer loop goes on.
  • break stands alone on its line, like every control statement.
  • A break outside a for or a while is an error.

Diagnostics

  • E0308: there is no open for or while to leave.
  • E0309: the keyword shares its line with other input.

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.

See also


James 0.3.1.

This site uses Just the Docs, a documentation theme for Jekyll.