---
title: "range-value-capture"
description: "Detect closures that capture reused range variables."
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.

# range-value-capture

**Default severity:** `warning`

Before Go 1.22, variables declared by a range clause were reused across
iterations. Variables assigned with `=` are still reused on every Go version.
A closure that outlives an iteration can therefore observe a later value.
Immediately invoked closures are accepted.

## Bad

```go
var value int
for _, value = range values {
	callbacks = append(callbacks, func() { use(value) })
}
```

## Good

```go
for _, value := range values {
	go func(current int) {
		use(current)
	}(value)
}
```

Source: https://strider.gempir.com/analyzers/range-value-capture/index.mdx
