num := 1
for num <= 3 {
log.Println(num)
num++
}
for n := 1; n <= 3; n++ {
log.Println(n)
}
for true {
log.Println(“我是一个死循环”)
}
可以用来遍历数组,切片,map,string和channel
#遍历字符串
str := "www.packagemain.com"
for _, v := range str {
log.Println(string(v))
}
for k, v := range maps {
log.Println(k)
log.Println(v)
}
nums := []int{1, 2, 3}
for k, v := range nums {
fmt.Printf("key: %v , value: %v \n", k, v)
}