Logo

Programming-Idioms

History of Idiom 13 > diff from v22 to v23

Edit summary for version 23 by :

Version 22

2015-09-13, 12:18:13

Version 23

2015-09-13, 12:20:19

Idiom #13 Iterate over map keys and values

Print each key k with its value x from an associative array mymap

Idiom #13 Iterate over map keys and values

Print each key k with its value x from an associative array mymap

Imports
import "fmt"
Imports
import "fmt"
Code
for k, x := range mymap {
  fmt.Printf("Key=%v, Value=%v\n", k, x)
}
Code
for k, x := range mymap {
  fmt.Println("Key =", k, ", Value =", x)
}
Comments bubble
Do not rely on the order of the traversal ! The order is undefined and is intentionaly randomized by the Go runtime.
Comments bubble
Do not rely on the order of the traversal ! The order is undefined and is intentionaly randomized by the Go runtime.
Demo URL
http://play.golang.org/p/lxh4n6DQ3e
Demo URL
http://play.golang.org/p/5BMpuLiuXj