Loop
Type:
loop• Category:flow• Tags:loop,iteration,control,flow,cycle
Description
Execute iterations with continue/exit branches
Parameters
| Name | Type | Description | Required | Default |
|---|---|---|---|---|
max_iterations | number | Maximum number of iterations | no | 10 |
exit_condition | string | Expression for early exit (optional, e.g., 'vars.counter > 5') | no | |
check_after | boolean | If true, evaluate exit_condition after running the loop body (continue branch) | no | false |
loop_var | string | Variable name to store iteration counter in workflow vars | no | "loop_iteration" |
Help
Loop Worker
This worker implements loop control flow with two output branches for workflow routing.
How it works:
- Initialize: Set maximum iterations and optional exit condition
- Check conditions: Evaluate exit condition (pre- or post-body based on
check_after) and iteration count - Route execution:
- continue branch: When loop should proceed to next iteration (loops back)
- exit branch: When loop should terminate (exits loop)
Setting up the Loop:
- Connect previous workers → to Loop worker (entry point)
- Connect Loop worker "continue" → back to the beginning of loop tasks
- Connect Loop worker "exit" → to post-loop processing
Workflow Structure:
[Entry Tasks] → [Loop Worker] → continue → [Loop Tasks] → [Loop Worker]
↓ exit
[Exit Tasks]
Parameters:
- max_iterations: Maximum number of loop iterations (default: 10)
- exit_condition: Expression for early exit (optional, e.g., 'vars.counter > 5')
- check_after: If true, evaluate exit_condition after running the loop body (default: false)
- loop_var: Variable name to store iteration counter (default: "loop_iteration")
Branch Logic:
- continue: Returns
{"action": "continue", "next_iteration": N+1}- loops back - exit: Returns
{"action": "exit", "exit_reason": "..."}- exits loop
Example: Create a loop that processes items until condition met:
- Set max_iterations: 100
- Set exit_condition: 'vars.items_processed >= vars.total_items'
- Connect continue → back to data processing workers
- Connect exit → to final reporting worker
The workflow will cycle through the loop tasks until exit condition is met or max iterations reached.
Notes:
- exit_condition supports template braces: "{{ expr }}" (the braces are stripped before evaluation).
- The expression must evaluate to a boolean; prefer comparisons (>, >=, ==) rather than returning strings.
- Use safe accessors to avoid KeyError, e.g., vars.get('redis_n_ijnr', {}).get('result', 0) > 100.
- Use check_after=true to evaluate the condition after executing the continue branch (useful when the loop body computes the condition).
Examples:
- Pre-check (default): exit when counter reached total exit_condition: vars.get('items_processed', 0) >= vars.get('total_items', 0)
- Post-check: exit when Redis counter exceeds 100 after body exit_condition: vars.get('redis_n_ijnr', {}).get('result', 0) > 100 check_after: true