For the complete documentation index, see llms.txt. This page is also available as Markdown.

Iteration

loop

loop repeats a block a fixed number of times.

loop 3 (
  log "tick"
)

The count is evaluated once before the loop starts, so mutating any variable it depends on inside the body does not change how many times the body runs.

n = 3
loop n (
  n = n + 1 // does not extend the loop
)
// runs exactly 3 times

for Counted Loops

Use for name count when you need a one-based counter.

for i 3 (
  log i
)
// 1
// 2
// 3

Like loop, the count is evaluated once before the first iteration; changing a variable it was computed from inside the body has no effect on the iteration count.

for ... in

for ... in iterates over values. With two variable names, the first receives the one-based index or object key and the second receives the value.

Ranges also work with for ... in:

for ... of

for ... of iterates over keys or one-based indexes. With two variable names, the first receives the index/key and the second receives the value.

The old each keyword has been removed. Use for ... in for values or for ... of for indexes and keys.

break and continue

Use break to exit a loop early and continue to skip to the next iteration.

Last updated