Last active
October 23, 2016 15:20
-
-
Save kobayashi/38b81d5c3fda0202104e60eaf456c6a7 to your computer and use it in GitHub Desktop.
understand underscore
This file contains 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() { | |
s := []int{10, 20, 30, 40, 50, 60, 70, 80, 90} | |
fmt.Println(“--------\nindexWithValue\n--------“) | |
indexWithValue(s) | |
fmt.Println(“--------\nindexOnly\n--------“) | |
indexOnly(s) | |
fmt.Println(“--------\nvalueOnly\n--------“) | |
valueOnly(s) | |
fmt.Println(“--------\nnoValue\n--------“) | |
noValue(s) | |
} | |
func indexWithValue(slice []int) { | |
for index, value := range slice { | |
fmt.Println(index, value) | |
} | |
} | |
func indexOnly(slice []int) { | |
for index := range slice { | |
fmt.Println(index) | |
} | |
} | |
func valueOnly(slice []int) { | |
for _, value := range slice { | |
fmt.Println(value) | |
} | |
} | |
func noValue(slice []int) { | |
for range slice { | |
fmt.Println(“foo”) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment