While Loop
The while loop also comes in four variations:
i = 10while i > 0 print i i -= 1
while running == true do my_function!i = 10while i > 0 print i i -= 1
while running == true do my_function!i = 10until i == 0 print i i -= 1
until running == false do my_function!i = 10until i == 0 print i i -= 1until running == false do my_function!Like for loops, the while loop can also be used as an expression. While and until loop expressions support break with multiple return values.
value, doubled = while true n = get_next! break n, n * 2 if n > 10value, doubled = while true n = get_next! break n, n * 2 if n > 10Additionally, for a function to return the accumulated value of a while loop, the statement must be explicitly returned.
Repeat Loop
Section titled “Repeat Loop”The repeat loop comes from Lua:
i = 10repeat print i i -= 1until i == 0i = 10repeat print i i -= 1until i == 0Repeat loop expressions also support break with multiple return values:
i = 1value, scaled = repeat break i, i * 100 if i > 3 i += 1until falsei = 1value, scaled = repeat break i, i * 100 if i > 3 i += 1until false