循环
package main
import "fmt"
func main() {
for i:=0; i < 6; i++ {
fmt.Printf("%d\n", i)
}
}
执行结果:
0
1
2
3
4
5
遍历数组
package main
import "fmt"
func main() {
var arr = [6]int{1,3,5,7,9,1}
for index, value := range arr {
fmt.Printf("%v -> %v\n", index, value)
}
}
运行结果:
0 -> 1
1 -> 3
2 -> 5
3 -> 7
4 -> 9
5 -> 1