Stop Loop stage
Overview
Stop loop exits a loop early based on a counter, allowing you to break out of a Loop stage before all items have been processed. Use this stage to implement early termination logic in batch processing or stop after finding a specific item.
Configuration
Required Fields
| Field | Description | Example |
|---|---|---|
| Stop loop when this stage runs (times) | Number of times this stage can run before stopping the loop | 1 (stop immediately), 10 (stop after 10 runs), {{maxIterations}} |
Exit Points
| Exit | When |
|---|---|
| Pass | Always executes when stage runs - decrements counter and continues |
Loop Behavior: When counter reaches 0 or less, the Loop stage exits via its Pass exit after current iteration completes.
How It Works
When executed, the stage:
- Retrieves counter value - Gets configured loop counter (or existing counter from previous run)
- Decrements counter - Reduces counter by 1
- Stores updated counter - Saves decremented value for Loop stage to check
- Loop checks counter - Loop stage checks if counter ≤ 0 after iteration
- Breaks if needed - Loop exits via Pass when counter reaches 0 or less
Key behavior: Loop doesn't break immediately - breaks after current iteration completes.
Common Use Cases
1. Stop on First Match
Search for a specific customer and stop when found.
Loop Iterate Path:
- Route Flow: {{found}} equals YES
- Pass: Stop loop (counter: 1)
- Fail: Continue to next iteration
Result: Loop exits after finding the target customer, skipping remaining items.
2. Process Only First 10 Items
Process only the first 10 records in a large dataset.
Loop Iterate Path:
- Process record (any stages)
- Stop loop (counter: 10)
Result: Only first 10 items processed, remaining items skipped.
3. Conditional Early Exit
Stop processing if running total exceeds budget.
Loop Iterate Path:
- Increment Number: Add {{expenseAmount}} to runningTotal
- Route Flow: {{runningTotal}} greater than {{BudgetLimit}}
- Pass: Stop loop (counter: 1)
- Fail: Continue
Result: Loop exits as soon as running total exceeds budget.
4. Stop After N Successful API Calls
Make API calls until 5 succeed, then stop.
Loop Iterate Path:
- Call API
- Pass: Increment successCount by 1
- Error: Continue to next
- Route Flow: {{successcount}} >= 5
- Pass: Stop loop (counter: 1)
Result: Loop exits after 5 successful API calls.
Key Behaviors
| Feature | Behavior |
|---|---|
| Counter Decrement | Decrements each time Stop loop stage runs |
| Break Timing | Loop breaks after current iteration completes (not immediately) |
| Loop Exit | Loop exits via Pass exit (not a special "break" exit) |
| Counter Scope | Counter is global to flow - affects innermost active loop in nested loops |
| Multiple Stop Loops | If multiple Stop loop stages run, they share the same counter (last one wins) |
| Zero/Negative Counter | ✓ Counter ≤ 0 causes loop to break (normal behavior) |
Conditional Breaking Pattern
Stop loop has no built-in conditional logic. For conditional breaking, combine with Route Flow:
Pattern:
- Route Flow: Check condition
- Pass (condition met): → Stop loop
- Fail (condition not met): → Continue loop
Best Practices
- ✓ Use counter value 1 for immediate break (stop on first execution)
- ✓ Use higher counter values to limit iterations (e.g., 10 for first 10 items)
- ✓ Combine with Route Flow for conditional breaking logic
- ✓ Place Stop loop strategically in iterate path (after condition check, before remaining processing)
- ✓ Use with Increment Number to track processed items
- ✓ Test with both small and large datasets to verify break behavior
- ✓ Remember break happens after current iteration completes
Common Mistakes
| Mistake | Symptom | Fix |
|---|---|---|
| Expecting immediate break | Current iteration completes before loop exits | This is correct behavior - loop breaks after iteration completes, not mid-iteration |
| Not using Route Flow for conditions | Loop breaks unconditionally instead of conditionally | Place Route Flow before Stop loop to add conditional logic |
| Wrong counter value | Loop breaks too early or too late | Counter 1 = stop immediately; higher values = stop after N runs |
| Multiple Stop loops interfering | Unexpected break behavior in complex flows | Use only one Stop loop per loop; they share the same counter |
| Expecting special break exit | Can't find "break" exit on Loop stage | Loop exits via its Pass exit when break occurs (not a separate exit) |
Troubleshooting
| Issue | Common Cause | Fix |
|---|---|---|
| Loop never breaks | Stop loop stage not being reached in iterate path | Verify Stop loop is on the execution path; check Route Flow conditions |
| Loop breaks too early | Counter value too small or multiple Stop loops running | Increase counter value; remove extra Stop loop stages |
| Current item still processes after break | Misunderstanding break timing | This is correct - loop completes current iteration before breaking |
| Nested loop breaks unexpectedly | Counter is flow-global, affects innermost active loop | Design nested loops carefully; inner loop's Stop loop affects inner loop |
Do's and Don'ts
Do:
- ✓ Use counter 1 for immediate break
- ✓ Combine with Route Flow for conditional breaking
- ✓ Place strategically in iterate path
- ✓ Remember break happens after current iteration
- ✓ Test with different dataset sizes
Don't:
- ✗ Expect immediate mid-iteration break
- ✗ Use multiple Stop loop stages in same loop (they interfere)
- ✗ Look for special "break" exit on Loop stage (uses Pass exit)
- ✗ Forget that counter is flow-global in nested loops
Edge Cases
- Counter Zero: Setting counter to 0 breaks immediately after first execution.
- Negative Counter: Treated same as zero - breaks immediately.
- Very High Counter: No maximum - counter can be any positive integer.
- Counter with Variables: Can use {{maxIterations}} for dynamic counter values.
- Nested Loops: Counter is flow-global - affects innermost active loop only.
- Multiple Stop Loops: If multiple Stop loop stages run, they share counter - last one sets final value.
Related Stages
- Loop: The stage that Stop loop works with to control iteration
- Route Flow: Add conditional logic before Stop loop
- Increment Number: Track how many items processed before break
- Return true/false: Exit entire flow (not just loop)