DRAFTThis page is not published. Only visible in development mode.

Loop, Break & Continue

loop repeats its block with no condition of its own - it runs until a break ends it. That makes it the shape for "repeat until done", where the exit condition emerges mid-iteration rather than up front. break and continue are not tied to loop: they steer while and for loops the same way.

loop runs until break

The block executes over and over; break exits immediately, and whatever the variables hold at that moment is what you keep. Here the exit condition depends on the value being computed - exactly the case a condition-first loop states awkwardly:

$ loop Runs Until break
$ ctrl+enter to run

continue skips to the next iteration

continue abandons the rest of the current iteration and jumps straight back to the top. Statements after it - including writes - simply do not run for that pass. Note the ; after each if ... { ... } block before the next statement:

$ continue Skips to the Next Iteration
$ ctrl+enter to run

Carry a result out of the loop

Variables declared before the loop survive it; variables declared with let inside the block are scoped to one iteration. Accumulate into outer variables, use them after break:

$ Carry a Result Out of the Loop
$ ctrl+enter to run

break and continue work in every loop

A while loop can bail out before its condition turns false:

$ break Exits a while Loop Early
$ ctrl+enter to run

And continue inside a for loop acts as a per-iteration filter:

$ continue Filters a for Loop
$ ctrl+enter to run

There is no infinite loop

A loop with no reachable break does not hang the engine. Iteration is capped at 10,000; exceeding the cap fails the request with RUNTIME_006, and the failed request rolls back like any other error:

$ A Loop That Never Breaks Is an Error
$ ctrl+enter to run
Loops are statements, not transforms
Loops iterate variables and statements, not rows. To transform rows, prefer the pipeline - filter, map, aggregate - and reach for a loop when the logic is genuinely iterative. The other constructs are on the Control Flow overview.