endwhile

The endwhile command ends the body of a while loop.

Syntax

endwhile

endwhile takes no arguments and stands alone on its line.

What it does

The preprocessor closes the loop that the matching while opened. Before each pass it tests the loop’s expression again, and after the last pass it reads on from the next line.

When James applies it

By the preprocessor, when it is read. The body is repeated before the parser sees it. A while is resolved before the phase of the parser matters, so it is legal anywhere.

Rules James adds

  • Every while must close with its own endwhile in the file that opened it.
  • A closer that crosses another construct is reported once, and one later endwhile is forgiven.

Diagnostics

  • E0303: there is no open while for it to close.
  • E0307: it crosses another construct instead of closing the innermost one.
  • E0309: the keyword shares its line with other input.
  • E0316: the open construct is not a while.
  • E0319: a while reaches the end of its file without an endwhile.
  • E0312: raised once the loop has run 1,000,000 passes.
  • E0310: raised on the opening while, when more than 64 constructs are open.
  • E0318: raised on the opening while, when it ends with then.
  • E0321: raised when the loop is entered inside another command.

Example

The script tests/corpus/162-while-counts-down/input.tg, which make test runs:

c a while loop counts n down from 3 to 0, so its body appears three times
para n 3;
while(%n.gt.0)
para n [%n - 1];
endwhile

n starts at 3 and the body takes one from it. The test is true for 3, 2 and 1, so the body runs three times. The prep dump shows para n 3; and then para n 2;, para n 1; and para n 0;, one per pass.

See also


James 0.3.1.

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