You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
447 B
32 lines
447 B
package main
|
|
|
|
import "fmt"
|
|
|
|
func main() {
|
|
|
|
nums := []int{2, 3, 4}
|
|
sum := 0
|
|
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"}
|
|
for k, v := range kvs {
|
|
fmt.Printf("%s -> %s\n", k, v)
|
|
}
|
|
|
|
for k := range kvs {
|
|
fmt.Println("key:", k)
|
|
}
|
|
|
|
for i, c := range "go" {
|
|
fmt.Println(i, c)
|
|
}
|
|
}
|
|
|