Go 1.22 Released: Loop Variable Fix and Range Over Integers
Go 1.22 resolved the long-standing loop variable gotcha, added ranging over integers, and enhanced the net/http router with method and wildcard patterns.
Historical Archive. This article documents an event from 2024 and is preserved with its original date for reference. It is not current news, and details may have changed since publication.
What happened
Go 1.22 was released on February 6, 2024, as announced on the official Go blog. It shipped two notable language changes along with performance and standard-library improvements, and is best remembered for finally fixing one of Go's most famous gotchas.
The loop variable fix
For years, Go's for loops shared a single loop variable across all iterations, which surprised developers who captured the variable inside a goroutine or closure and found every iteration observing the final value. Starting with Go 1.22, each iteration gets its own copy of the loop variable, so the common pattern of launching goroutines inside a range loop now behaves as most people expect. The Go team paired this with tooling to help keep existing code from breaking.
Ranging over integers
Go 1.22 added the ability to range over an integer, so a loop can be written as for i := range 10 to iterate from 0 to 9. This is a small syntactic convenience that removes boilerplate for simple counting loops and paved the way for the range-over-function iterators that followed in Go 1.23.
Standard-library and performance improvements
The release enhanced the net/http router so that patterns can specify methods and wildcards, for example matching only GET requests and capturing a path segment, reducing the need for third-party routers in simple cases. It also added the math/rand/v2 package with a cleaner API and better algorithms, and delivered runtime memory optimisations that improve CPU performance by a small margin while reducing memory overhead.
Why it mattered
Go 1.22's loop variable change removed a persistent source of subtle bugs that had tripped up beginners and experts alike, arguably its most impactful change in years. Combined with integer ranging and a more capable standard router, it made everyday Go a little safer and more ergonomic without breaking the language's compatibility promise.
Related on Skillo
See also: Go 1.23's range-over-function iterators.
Sources
Published date reflects the original event date (2024-02-06). This article is original Skillo editorial written from the sources above; facts were verified in September 2026.
Written by
Skillo Staff
0 Comments
Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.