---
title: "single-iteration-loop"
description: "Detect loops that always exit during their first iteration."
image: "https://strider.gempir.com/og.png"
---

> Documentation Index
> Fetch the complete documentation index at: https://strider.gempir.com/llms.txt
> Use this file to discover all available pages before exploring further.

# single-iteration-loop

**Default severity:** `warning`

A loop whose top-level control flow always returns or breaks after a
conditional branch cannot begin a second iteration. This usually means the
exit was placed outside the intended branch.

Map ranges and one-statement loops are accepted because selecting a single
arbitrary or first element is a common intentional pattern.

## Bad

```go
for _, value := range values { if done(value) { use(value) }; return }
```

## Good

```go
for _, value := range values { if done(value) { break }; use(value) }
```

Source: https://strider.gempir.com/analyzers/single-iteration-loop/index.mdx
