A Tour of Go Range

The range form of the for loop iterates over a slice or map.

package main

import "fmt"

var pow = []int{1, 2, 4, 8, 16, 32, 64, 128}
func main() {
    for i, v := range pow {
        fmt.Printf("2**%d = %d\n", i, v)
    }
}

 

posted @ 2014-10-27 01:56  wuhn  阅读(160)  评论(0编辑  收藏  举报