break
The break statement is used to exit a loop early.
It can be used with repeat, while, and for loops,
as well as on and with blocks.
let x = 0
while true {
Transmission { %(x) }
x += 1
if x == 5 {
break
}
}
// Outputs 0, 1, 2, 3, 4
Returning Values
Pass an expression to break to specify the resulting value of the loop expression.
let a = loop {
if Tick > 10s {
break 99
}
await Tick
}
// a is now `99`
Returning Multiple Values
You can pass multiple values to break to return multiple values:
let x, y, z = loop {
if Tick > 10s {
break 1, 2, 3
}
await Tick
}
// x is 1, y is 2, z is 3