Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. package main
  2. import “fmt”
  3. func main() {
  4. s := []int{10, 20, 30, 40, 50, 60, 70, 80, 90}
  5. fmt.Println(“--------\nindexWithValue\n--------“)
  6. indexWithValue(s)
  7. fmt.Println(“--------\nindexOnly\n--------“)
  8. indexOnly(s)
  9. fmt.Println(“--------\nvalueOnly\n--------“)
  10. valueOnly(s)
  11. fmt.Println(“--------\nnoValue\n--------“)
  12. noValue(s)
  13. }
  14.  
  15. func indexWithValue(slice []int) {
  16. for index, value := range slice {
  17. fmt.Println(index, value)
  18. }
  19. }
  20.  
  21. func indexOnly(slice []int) {
  22. for index := range slice {
  23. fmt.Println(index)
  24. }
  25. }
  26.  
  27. func valueOnly(slice []int) {
  28. for _, value := range slice {
  29. fmt.Println(value)
  30. }
  31. }
  32.  
  33. func noValue(slice []int) {
  34. for range slice {
  35. fmt.Println(“foo”)
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement