Skip to content

Condition and branching

One check — two roads. How a program stops being a straight line

jump has four fields: where to jump, which condition, and the two values being compared. The line reads as “if stock is greater than or equal to ten — go there”.

If the condition holds, the next line to run is the one the arrow points at. If it does not, the ordinary next one runs and the program carries on as if nothing had happened.

Press “step” four times.

tick 0
Set0
=
Jump -> 41
if
Set2
=
End3
Set4
=
@counter0number
stocknullnull
lownullnull

stock holds a seven and the condition asks about ten: it is false, there is no jump, and the program reaches set low 1. The “there is enough stock” branch stayed aside — execution never got to it.

The target is set by an arrow, not a number

Section titled “The target is set by an arrow, not a number”

In the program’s text a jump’s target is a line number, but numbers are not written in the blocks: a jump line has an arrow on the left, and you drag it onto the line you want. While you drag, the lines light up.

That is not for looks. Numbers shift every time a line is added or deleted, and an arrow holds onto the line itself: insert something in the middle and the target is unchanged, so the jump still leads where it should.

The example’s third line is end, and without it the program, having landed in the “low” branch, would fall through into the “enough” branch and run both.

That is branching’s main trap: lines do not know they belong to somebody’s branch. Execution does not stop at the boundary — it simply carries on down the list. So a branch has to be left deliberately: either with end or with another jump.

There are eight conditions. The list names them in English, and the line itself shows not a name but a sign — two different labels, and both are worth knowing:

Condition In the block When it jumps
equal == the values are equal
notEqual not they are not equal
lessThan < less
lessThanEq <= less than or equal
greaterThan > greater
greaterThanEq >= greater than or equal
strictEqual === equal and of one kind: tells emptiness from zero
always always always; the comparison fields disappear

jump compares exactly as op does: with the same slack in the sixth decimal place and the same rules for null. The details are in the lesson «Comparisons and logic».

The always condition jumps every time, and the comparison fields disappear from the line — there is nothing to compare.

It is needed in two places: to close a loop whose check is at the top, and to leave a branch for wherever the common part of the program resumes. The second happens more often than it seems: end starts the iteration over, while always lets you carry on from the right place.

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.