Loop
A repeating section of code.

While

The while section is the simplest loop. It will run the code section indefinitely, as long as the condition is met.
1
while %Boolean%:
2
// run if passed
3
// run after exit
Copied!
The section will be run only if the condition is true, and will run as long as the condition is true.
If the condition is always true, the section will be run indefinitely.
1
while 1 is 1:
2
print "yes"
3
print "never met"
Copied!
Because of this, users will want some kind of exit condition.
1
set {var} to 0
2
while {var} is less than 10:
3
print "yes"
4
set {var} to {var} + 1
5
print {var}
Copied!
You can also exit the loop using the exit section effect.
1
while true:
2
print "run once"
3
exit section
4
print "never run"
5
print "continues here"
Copied!
You can skip the current iteration using the continue loop effect.
1
while true:
2
print "run infinitely"
3
continue current loop // jumps back to top of loop
4
print "never run"
5
print "never reached"
Copied!

Loop X Times

This is a very simple loop that will run a given number of times before finishing, with no conditions or requirements.
1
loop %Number% times:
2
// run %Number% times
3
// run after finished
Copied!
This can be used to avoid repeating a piece of code multiple times.
1
loop 10 times:
2
print "hello" // will be run 10 times
3
print "goodbye"
Copied!
You can also exit the loop using the exit section effect.
1
loop 10 times:
2
print "run once"
3
exit section // will exit during the First loop
4
print "never run"
5
print "continues here"
Copied!
You can skip the current iteration using the continue loop effect.
1
loop 10 times:
2
print "hello"
3
continue current loop // jumps back to top of loop
4
print "never reached"
5
print "goodbye"
Copied!

Loop X in Y

The iterable loop is the most common loop type, and is very useful for dealing with lists and other collections of data.
1
loop %Variable% in %Object%:
2
// run for each item in the list
3
// run after completion
Copied!
Although this accepts any object, it is designed to take a list, array or some variety of collection.
1
loop {item} in {list}:
2
print {item} // this is the value
Copied!
For each item in the list, that item is put into the {item} variable for the loop iteration.
1
loop {number} in {list_of_numbers}:
2
print "The number is " + {number}
3
print "Done!"
Copied!
An implicit array may also be used as the list to loop.
1
loop {number} in (1, 2, 6, 4):
2
print "The number is " + {number}
3
print "All four lucky numbers were printed."
Copied!
The first argument is used to store the object during the loop.
1
set {var} to "hello"
2
loop {var} in (1, 2, 3):
3
print {var} // will not be "hello" anymore
4
assert {var} is less than 4
5
assert {var} is not "hello"
6
assert {var} is 3 // the last element from the loop
Copied!
This can be used in conjunction with the function set behaviour to pass loop values to a function automatically.
1
function my_func(var):
2
trigger:
3
print {var}
4
​
5
loop my_func(null) in ("hello", "there")
6
// the `null` argument is replaced by the loop value when the loop runs
Copied!
This example uses the inline form of the loop section.
​