Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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”)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement