---
title: "Stop Loop"
url: "https://help.flows.world/en/article/stop-loop-stage"
language: "en"
last_updated: "2026-09-19T06:47:35.858Z"
---

# Stop Loop

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

![](https://cdn-assets.productfruits.com/31e1f09c-bac2-4064-9c78-a0d69a7cb9be)

**Where to find it:** *Flow Control* in the stage library.

## 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}}` |

**Using functions in these fields:** Any value field above accepts `@` functions, for example `@NowSecond` for the current time or `@calc(...)` for a calculation. 

See [Flows Functions](https://help.flows.world/en/article/flows-functions) for the full list.

## 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:

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: `{{customer.id}}` equals `{{targetCustomerId}}`
    -   **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 `{{expense.amount}}` 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:**

1.  **Route Flow:** Check condition
    -   **Pass (condition met):** → Stop loop
    -   **Fail (condition not met):** → Continue loop

![](https://cdn-assets.productfruits.com/7c959bbf-c8ce-4d26-991d-a6eabb10d788)

## 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) |
| Running Stop loop before or outside a loop | The next Loop in the flow breaks immediately, processing zero items | The break counter leaks forward into the next Loop. Only place Stop loop inside the loop it should control, never before a loop |

## 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.
-   **Before/Outside a Loop:** Stop loop still sets the break counter even with no loop running. That counter persists and the next Loop reads it, breaking immediately with zero items. Only use Stop loop inside the loop it controls.

## Related Stages

-   [**Loop**](https://help.flows.world/en/article/loop)**:** The stage that Stop loop works with to control iteration
-   [**Route Flow**](https://help.flows.world/en/article/route-flow)**:** Add conditional logic before Stop loop
-   [**Increment Number**](https://help.flows.world/en/article/increment-number)**:** Track how many items processed before break
-   [**Return true**](https://help.flows.world/en/article/return-true) **/** [**Return false**](https://help.flows.world/en/article/return-false)**:** Exit entire flow (not just loop)
