Book
Control
If, loops, break, continue, and match.
Condition chains
? starts a chain. : expr { } is else-if. : { } is else.
/ std/io
$ n = 3
? n == 0 {
io.print('zero')
}
: n == 1 {
io.print('one')
}
: {
io.print('many')
}Loops
* { } loops forever. * cond { } is while. * item : items { } walks a list or inclusive range. < breaks; > continues.
/ std/io
/ std/str
~ i = 0
* i < 3 {
io.print(str.from_int(i))
~ i = i + 1
}
$ xs = [10, 20, 12]
~ sum = 0
* x : xs {
~ sum = sum + x
? x == 20 {
<
}
}
io.print(str.from_int(sum))Match
| expr { arms } matches. Value arms compare deeply and may group alternatives with commas. Inclusive ranges test membership, and % name selects a named struct type. Default is : { body }. Result and option arms are covered on the next page.