Range continued

You can skip the index or value by assigning to _.

  1. for i, _ := range pow
  2. for _, value := range pow

If you only want the index, you can omit the second variable.

  1. for i := range pow

range-continued.go

  1. package main
  2. import "fmt"
  3. func main() {
  4. pow := make([]int, 10)
  5. for i := range pow {
  6. pow[i] = 1 << uint(i) // == 2**i
  7. }
  8. for _, value := range pow {
  9. fmt.Printf("%d\n", value)
  10. }
  11. }