Control Flow
if
if condition {
value_a
} else {
value_b
}
if is expression-oriented.
while
while condition {
work()
}
The condition must evaluate to Bool.
for
for consumes any value that can be converted to an iterator:
for x in [1, 2, 3] {
print(x)
}
Ranges and strings can also be used directly:
for x in (1..5) {
print(x)
}
for ch in "hello" {
print(ch)
}
break
while true {
if done {
break
}
}
continue
for x in xs {
if x < 0 {
continue
}
print(x)
}
continue is loop-local control flow and must not escape a function/module boundary.
return
f = |x| {
if x < 0 {
return 0
}
x
}
A return used where a value is required is rejected by the evaluator. Function calls preserve return flow correctly.