Pelago
Control flow

Control flow

Choosing and repeating: if, unless, while, for, loop, break and continue, guard, defer and tail calls, one page each.

FeatureWhat it doesPage
if, else, ?:Choose between branches; if is also an expression.if and else
unlessif with the condition turned around.unless
whileRepeat while a condition holds.while
forWalk a range, a list, a map, a string or any iterator.for
a..bRanges, step, and what they can and cannot do.Ranges
loopRepeat until break; the only loop that gives a value.loop
break, continue, labelsLeave or skip, including outer loops.break, continue and labels
guardCheck a condition up front and leave early.guard
deferRun code when the scope ends.defer
becomeA guaranteed tail call.Tail calls

Pattern matching with switch and is has its own chapter: Pattern matching.

Every condition must be a bool. There is no truthy or falsy value: if n { ... } with an int is an error.