Skip to Content
WorkflowsLoops & Iteration

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:

FieldDescription
ArrayExpression that resolves to an array (e.g., {{leads}})
Item variableVariable name for the current item (default: item)
Index variableVariable 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:

FieldDescription
CountNumber of iterations (e.g., 5 or {{variable}})
Index variableVariable 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 seconds

While Mode

Repeats the loop body as long as a condition is true. The condition is evaluated before each iteration.

Configuration:

FieldDescription
ConditionExpression that must be true to continue (e.g., {{hasMore}} === true)
Max iterationsSafety 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

ConsiderationRecommendation
Large arrays (100+ items)Use bulk operation nodes instead of looping with single-item actions
API rate limitsAdd a Delay node inside the loop to respect external rate limits
While loopsAlways set a max iteration limit to prevent infinite loops
Execution timeLoops count toward the 30-minute max execution time