Loop
Process a list of items by executing the same step repeatedly, handling each element one at a time in sequence.
Enabling Loop
To enable looping for a step:
- Click the step’s options menu (⋮)
- Click
Add Loop
- Enter a loop expression that determines how the step iterates
Loop Expression
- A JavaScript expression that returns the next item to process
- Returns
null
,undefined
, orfalse
to terminate the loop - Has access to special variables:
index
: Current iteration number (starts at 0)item
: Current value being processed
Loop Output
- When loop is enabled, the step’s output becomes an array
- Each array element contains the output from one iteration
- Output array maintains the order of processing
Loop Expression Rules
- Return one item at a time from the array:
return items[index];
- Never return the full array (causes infinite loop)
Accessing Output
When a step has looping enabled, its output becomes an array containing results from each iteration:
When accessing the output of a looped step in code steps, you must use array methods like map()
to access individual iteration results.
Loop Termination
Loop stops when the expression returns null
, undefined
, or false
.
Array bounds automatically handle termination:
Examples
Here are some practical examples demonstrating how to use loops in your workflows:
Parallel API Requests
Process multiple API endpoints simultaneously:
File Batch Processing
Process multiple files with consistent logic:
This eliminates the need for separate model steps for each file.
Remove Loop
To remove a loop from a step:
- Click the step’s options menu (⋮)
- Click
Remove Loop