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

FieldDescriptionExample 
Stop loop when this stage runs (times)Number of times this stage can run before stopping the loop1 (stop immediately), 10 (stop after 10 runs), {{maxIterations}}

Exit Points

ExitWhen 
PassAlways 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:

  1. Retrieves counter value - Gets configured loop counter (or existing counter from previous run)
  2. Decrements counter - Reduces counter by 1
  3. Stores updated counter - Saves decremented value for Loop stage to check
  4. Loop checks counter - Loop stage checks if counter ≤ 0 after iteration
  5. 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

FeatureBehavior 
Counter DecrementDecrements each time Stop loop stage runs
Break TimingLoop breaks after current iteration completes (not immediately)
Loop ExitLoop exits via Pass exit (not a special "break" exit)
Counter ScopeCounter is global to flow - affects innermost active loop in nested loops
Multiple Stop LoopsIf 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:

  1. 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

MistakeSymptomFix 
Expecting immediate breakCurrent iteration completes before loop exitsThis is correct behavior - loop breaks after iteration completes, not mid-iteration
Not using Route Flow for conditionsLoop breaks unconditionally instead of conditionallyPlace Route Flow before Stop loop to add conditional logic
Wrong counter valueLoop breaks too early or too lateCounter 1 = stop immediately; higher values = stop after N runs
Multiple Stop loops interferingUnexpected break behavior in complex flowsUse only one Stop loop per loop; they share the same counter
Expecting special break exitCan't find "break" exit on Loop stageLoop exits via its Pass exit when break occurs (not a separate exit)

Troubleshooting

IssueCommon CauseFix 
Loop never breaksStop loop stage not being reached in iterate pathVerify Stop loop is on the execution path; check Route Flow conditions
Loop breaks too earlyCounter value too small or multiple Stop loops runningIncrease counter value; remove extra Stop loop stages
Current item still processes after breakMisunderstanding break timingThis is correct - loop completes current iteration before breaking
Nested loop breaks unexpectedlyCounter is flow-global, affects innermost active loopDesign 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)

Was this article helpful?