Fixing For Loops in Go 1.22.21 includes a preview of a change to loop scoping that we plan to ship in Go1.22. The change will fix the examples above, so that they are no longer buggy Go programs; it will end the production problems caused by such mistakes.

5m read timeFrom go.dev
Post cover image
Table of contents
The Go BlogFixing For Loops in Go 1.22

Sort: