﻿---
title: Loop break
description: Reference for the loop.break step, which exits the innermost enclosing foreach or while loop.
url: https://docs-v3-preview.elastic.dev/elastic/docs-content/tree/main/explore-analyze/workflows/steps/loop-break
products:
  - Elastic Cloud Enterprise
  - Elastic Cloud Hosted
  - Elastic Cloud Serverless
  - Elastic Cloud on Kubernetes
  - Elastic Stack
  - Kibana
applies_to:
  - Elastic Cloud Serverless: Generally available
  - Elastic Stack: Planned
---

# Loop break
The `loop.break` step exits the innermost enclosing [`foreach`](https://docs-v3-preview.elastic.dev/elastic/docs-content/tree/main/explore-analyze/workflows/steps/foreach) or [`while`](https://docs-v3-preview.elastic.dev/elastic/docs-content/tree/main/explore-analyze/workflows/steps/while) loop immediately. Use it to stop iterating once a condition is met, for example when you want to process items until you find the first critical match and then move on.

## Parameters

The `loop.break` step takes no step-specific parameters; only the standard `name` and `type` fields required on every step.

| Parameter | Location  | Type   | Required | Description             |
|-----------|-----------|--------|----------|-------------------------|
| `name`    | top level | string | Yes      | Unique step identifier. |
| `type`    | top level | string | Yes      | Must be `loop.break`.   |


## Example: Stop on first critical match

```yaml
- name: find_critical
  type: foreach
  foreach: "${{ event.alerts }}"
  steps:
    - name: check_critical
      type: if
      condition: "foreach.item.kibana.alert.severity : critical"
      steps:
        - name: record_and_exit
          type: cases.addComment
          with:
            case_id: "{{ consts.triage_case_id }}"
            comment: "First critical alert found at position {{ foreach.index }}"
        - name: exit
          type: loop.break
```

The loop terminates as soon as the first critical alert is processed.

## Related

- [Flow control steps](https://docs-v3-preview.elastic.dev/elastic/docs-content/tree/main/explore-analyze/workflows/steps/flow-control-steps): Overview of all flow-control types.
- [Loop continue step](https://docs-v3-preview.elastic.dev/elastic/docs-content/tree/main/explore-analyze/workflows/steps/loop-continue): Skip to the next iteration instead of exiting.
- [Foreach step](https://docs-v3-preview.elastic.dev/elastic/docs-content/tree/main/explore-analyze/workflows/steps/foreach) and [While step](https://docs-v3-preview.elastic.dev/elastic/docs-content/tree/main/explore-analyze/workflows/steps/while): The loop types `loop.break` can exit from.