# error: test failed: all goroutines captured same loop variable value

- **ID:** `go/range-loop-variable-capture`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Before Go 1.22, the loop variable is shared across iterations. Closures or goroutines launched in a for loop capture the same variable, so they all see the final value.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.18 | active | — | — |
| 1.19 | active | — | — |
| 1.20 | active | — | — |
| 1.21 | active | — | — |

## Workarounds

1. **** (97% success)
   ```
   for _, v := range items {
    v := v
    go func() { use(v) }()
}
   ```
2. **** (95% success)
   ```
   // go.mod: go 1.22
for _, v := range items {
    go func() { use(v) }()
}
   ```

## Dead Ends

- **** — Non-deterministic; the variable still changes under the goroutine and results vary. (85% fail)
- **** — Does not change the fact that the variable is shared; masking the race. (80% fail)
