End
Start the iteration over — and, against expectations, without giving up the tick
end has no fields. It does exactly one thing: it puts the number of lines in the program into
@counter. That is past the edge, and a number past the edge resets the counter — so the
program starts from the first line.
Press “step” four times: loops becomes two and after stays empty. The line below end is
unreachable — execution never gets to it.
The program loops without it anyway
Section titled “The program loops without it anyway”That is the first thing to understand: end is not needed to make a program repeat. It
starts over by itself when the lines run out.
end is needed when an iteration has to be cut short early: to leave a branch without
running everything written below.
jump 4 greaterThanEq stock 100set low 1endset low 0Without the third line both branches would run one after the other. That is the lesson “Condition and branching”.
It does not give up the tick
Section titled “It does not give up the tick”Here is where the surprise lives. wait gives up the rest of the tick and end does not: it
only moves the counter. If the processor still has instructions in its budget, it goes straight
round the program again, in the same tick.
The same one-useful-line program on a hyper processor, 60 ticks:
| Tail | Iterations per second |
|---|---|
| nothing | 1475 |
end |
738 |
wait 0 |
59 |
end is twice as slow as an empty tail for exactly one reason: it counts as an instruction
itself, so the iteration went from one line to two. It gives no pause at all.
Unofficial fan project, not affiliated with Anuke. Mindustry sprites, fonts and translations © Anuke, used under GPL-3.0; Fira Code under OFL-1.1. Site code is GPL-3.0.