# error: expected result 3, got 3 (all goroutines see same loop variable)

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

## Root Cause

Before Go 1.22, goroutines launched inside a for loop captured the same loop variable, so all goroutines observed the final value. This causes subtle output bugs and races.

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   Shadow the loop variable: for _, v := range items { v := v; go func(){ use(v) }() }
   ```
2. **** (92% success)
   ```
   Upgrade to Go 1.22+ where loop variables are per-iteration by default, or pass v as an argument: go func(v T){...}(v)
   ```

## Dead Ends

- **** — The variable is shared; sleeping changes nothing about which value is read. (90% fail)
- **** — Scheduling does not affect variable capture semantics. (95% fail)
