Skip to content

Instantly share code, notes, and snippets.

@tucnak
Created October 28, 2015 10:09
Show Gist options
  • Save tucnak/027271a306c2e5271a77 to your computer and use it in GitHub Desktop.
Save tucnak/027271a306c2e5271a77 to your computer and use it in GitHub Desktop.
Range by reference? Haha.
package main
import "fmt"
func main() {
numbers := []int{0, 1, 2, 3, 4}
for _, number := range numbers {
number++
}
fmt.Println(numbers) // [0 1 2 3 4]
for i, _ := range numbers {
numbers[i]++
}
fmt.Println(numbers) // [1 2 3 4 5]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment