Loops & Iteration
The Loop node repeats a set of actions multiple times. It supports three modes depending on your use case: iterating over an array, repeating a fixed number of times, or looping while a condition is true.
Loop Modes
forEach Mode
Iterates over each item in an array. On each iteration, the current item and index are available as variables.
Configuration:
| Field | Description |
|---|---|
| Array | Expression that resolves to an array (e.g., {{leads}}) |
| Item variable | Variable name for the current item (default: item) |
| Index variable | Variable name for the current index (default: index) |
Example: Send a personalized message to each lead in a list:
Trigger: Manual
--> Set Variable: leads = [list of leads from API]
--> Loop (forEach): iterate over {{leads}}
--> Send Message: "Hi {{item.firstName}}, ..."
--> Log: "All messages sent"Available in loop body:
{{item}}— The current array element{{index}}— The zero-based iteration index{{loop.length}}— Total number of items
Count Mode
Repeats the loop body a fixed number of times.
Configuration:
| Field | Description |
|---|---|
| Count | Number of iterations (e.g., 5 or {{variable}}) |
| Index variable | Variable name for the current iteration (default: index) |
Example: Retry an API call up to 3 times:
Loop (count): 3 times
--> HTTP Request: POST https://external-api.com/webhook
--> Condition: {{httpResponse.status}} === 200
True --> Break
False --> Delay: 5 secondsWhile Mode
Repeats the loop body as long as a condition is true. The condition is evaluated before each iteration.
Configuration:
| Field | Description |
|---|---|
| Condition | Expression that must be true to continue (e.g., {{hasMore}} === true) |
| Max iterations | Safety limit to prevent infinite loops (default: 100) |
Example: Paginate through an API until no more pages:
Set Variable: page = 1, hasMore = true
--> Loop (while): {{hasMore}} === true
--> HTTP Request: GET /api/items?page={{page}}
--> Set Variable: page = {{page}} + 1
--> Set Variable: hasMore = {{httpResponse.data.pagination.totalPages}} > {{page}}Break Node
The Break node exits the current loop immediately, skipping any remaining iterations. Execution continues with the node after the loop.
Example: Find the first matching lead and stop:
Loop (forEach): iterate over {{leads}}
--> Condition: {{item.score}} > 90
True --> Set Variable: topLead = {{item}}
--> Break
False --> (continue to next iteration)Nesting Loops
Loops can be nested up to 3 levels deep. Each nested loop has its own scope for item and index variables.
Loop (forEach): iterate over {{teams}} as team
--> Loop (forEach): iterate over {{team.members}} as member
--> Send Email to {{member.email}}To avoid variable name conflicts in nested loops, use distinct variable names for each level (e.g., team, member instead of item for both).
Performance Considerations
| Consideration | Recommendation |
|---|---|
| Large arrays (100+ items) | Use bulk operation nodes instead of looping with single-item actions |
| API rate limits | Add a Delay node inside the loop to respect external rate limits |
| While loops | Always set a max iteration limit to prevent infinite loops |
| Execution time | Loops count toward the 30-minute max execution time |