Created
October 28, 2015 10:09
-
-
Save tucnak/027271a306c2e5271a77 to your computer and use it in GitHub Desktop.
Range by reference? Haha.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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