Logo

Programming-Idioms

History of Idiom 13 > diff from v3 to v4

Edit summary for version 4 by :

Version 3

2015-08-01, 17:22:56

Version 4

2015-08-18, 13:37:58

Idiom #13 Iterate over map keys and values

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

Idiom #13 Iterate over map keys and values

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

Imports
use std::collections::BTreeMap;
Code
for (key, val) in &mymap {
    println!("Key={key}, Value={val}", key=key, val=val);
}
Comments bubble
You can also print collections in a 'nice' way with `println!("{:?}", mymap);`.

This example works the same if you replace `BTreeMap` with `HashMap`.
Demo URL
http://is.gd/FnGX0Z