The Loop block is a container that runs the blocks inside it repeatedly — over each item in a collection, a fixed number of times, or while a condition holds. Drop blocks inside it, and they run once per iteration. Iterations run one after another; for concurrent work, use a Parallel block.
Loop Types
A For loop runs a fixed number of times. Set the iteration count.
A ForEach loop runs once per item in an array or object, exposing the current item as <loop.currentItem>.
A While loop runs as long as a condition is true. The condition is checked before each iteration, so the body may run zero times.
A Do-While loop runs the body once, then repeats while a condition is true. The condition is checked after each iteration, so the body always runs at least once.
Configuration
Set the loop type, then the value it needs:
- Iterations — how many times to run (For loops)
- Collection — the array or object to iterate (ForEach loops)
- Condition — the boolean expression to check (While and Do-While loops)
Referencing loop data
References differ inside the loop and after it.
Inside the loop, read the current iteration with <loop.*>:
<loop.index>— the iteration number, starting at 0<loop.currentItem>— the current item (ForEach only)<loop.items>— the full collection (ForEach only)
const idx = <loop.index>; // 0, 1, 2, ...
const item = <loop.currentItem>; // the current itemThese are only available to blocks inside the loop container.
After the loop, read the collected results by the loop block's name — not <loop.*>:
// a loop named "Process Items"
const all = <processitems.results>; // [result1, result2, ...]The name is normalized — lowercase, no spaces. <loop.*> only works inside.
Examples
A ForEach loop scores each review and collects the results; after the loop finishes, an Agent summarizes <loop.results>. The same container holds the blocks for any loop type:
- Process API results —
API (Fetch) → Loop (ForEach) → Agent (Analyze) → Function (Store) - Generate variations —
Loop (5×) → Agent (Generate) → Evaluator (Score) → Function (Select best) - Counter with While —
Variables (i=0) → Loop (While i<10) → Agent (Process) → Variables (i++)
Nesting and limits
Containers nest. You can place loops inside loops, parallels inside loops, and any combination, to build multi-dimensional workflows.
For and ForEach loops are capped at 1,000 iterations. While and Do-While loops run until their condition is false, with no hard cap — make sure the condition eventually becomes false so the loop ends.
Best Practices
- Use ForEach for collections. When you have an array or object, ForEach is clearer than a For loop with manual indexing.
- Keep iteration counts reasonable. Each iteration adds to total run time, since the loop runs sequentially.
- Reach for Parallel when order doesn't matter. Independent work over a collection runs faster in a Parallel block.
- Guarantee an exit. For While and Do-While loops, make sure the condition will become false.