endfor
The endfor command ends the body of a for loop.
Syntax
endfor
endfor takes no arguments and stands alone on its line.
What it does
The preprocessor closes the loop that the matching for opened and repeats the body up to it. Text after endfor is read once the last pass is done.
When James applies it
By the preprocessor, when it is read. The body is repeated before the parser sees it. A for is resolved before the phase of the parser matters, so it is legal anywhere.
Rules James adds
- Every
formust close with its ownendforin the file that opened it. - A closer that crosses another construct is reported once, and one later
endforis forgiven.
Diagnostics
- E0301: there is no open
forfor 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
for. - E0319: a
forreaches the end of its file without anendfor. - E0310: raised on the opening
for, when more than 64 constructs are open. - E0311: raised on the opening
for, when the step is zero. - E0312: raised on the opening
for, when it would run more than 1,000,000 passes.
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 runs up to 10 passes, and the break inside the when leaves it on the third. The prep dump shows para last 1;, para last 2; and para last 3;, and the endfor is gone.