Logo

Programming-Idioms

History of Idiom 13 > diff from v18 to v19

Edit summary for version 19 by :

Version 18

2015-09-13, 12:12:09

Version 19

2015-09-13, 12:12:52

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.Printf("Key=%v, Value=%v\n", k, x)
}
Comments bubble
Do not rely on the order of the traversal ! The order is undefined and is intentionaly randomized randomized by the Go team.
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/lxh4n6DQ3e