package main
import "fmt"
func main() {
nums := []int{2,3,4}
sum :=0
//rang 遍历切片
for _,num := range nums {
sum += num
}
fmt.Println("sum:",sum)
for i,num := range nums {
if num == 3 {
fmt.Println("index:",i)
}
}
kvs := map[string]string{"a":"apple","b":"banana"}
//range遍历map
for k,v := range kvs{
fmt.Printf("%s-> %s
",k,v)
}
//range遍历字符串
for i,c := range "go" {
fmt.Println(i,c)
}
//range还可以遍历channel
}