Contents

Roo

The break statement

Use can use the break statement to break out of a for or while loop early:

var a = 2
while (a += 1) < 20 {
    if (a == 10) break # goes to `print(a)`
}
print(a) #=> 10

The break keyword can be conditional by following it with the if keyword and then an expression:

var balance = 0
while True {
    print("Balance: £" + balance)
    balance += 1000
    break if balance > 9999
}