Item #32 Ignoring the impact of using pointer elements in range loops - not relevant after Go 1.22

Author: iypetrovCreated Jan 17, 2026Updated Jan 31, 2026
Labelscommunity mistake

Starting with Go 1.22, iteration variables declared by range loops are created anew for each iteration, instead of being reused across iterations. Because of this the first example with the Store and Client structs doesn't return

key=1, value=&main.Customer{ID:"3", Balance:0}
key=2, value=&main.Customer{ID:"3", Balance:0}
key=3, value=&main.Customer{ID:"3", Balance:0}

but

key=1, value=&main.Customer{ID:"1", Balance:10}
key=2, value=&main.Customer{ID:"2", Balance:-10}
key=3, value=&main.Customer{ID:"3", Balance:0}

https://go.dev/doc/go1.22#language

I think that a small comment on the code example is enough to warn the readers.