Values & References13 / 15
Up next

range gives copies

package main

import "fmt"

type Item struct{ Qty int }

func main() {
	items := []Item{{1}, {2}, {3}}
	// the range value is a copy; use the index to write back
	for i := range items {
		items[i].Qty *= 10
	}
	fmt.Println(items)
}
What you're solving

index to mutate elements in place