Associative array/Iteration: Difference between revisions

Content added Content deleted
(→‎{{header|Rust}}: Added output, formatted according to the guidelines)
Line 2,135: Line 2,135:
=={{header|Rust}}==
=={{header|Rust}}==
<lang Rust>use std::collections::HashMap;
<lang Rust>use std::collections::HashMap;

fn main() {
fn main() {
let mut squares = HashMap::new();
let mut squares = HashMap::new();
squares.insert("one", 1i32);
squares.insert("one", 1);
squares.insert("two", 4);
squares.insert("two", 4);
squares.insert("three", 9);
squares.insert("three", 9);
for key in squares.keys() {
for key in squares.keys() {
println!("Key {}", key);
println!("Key {}", key);
}
}
for value in squares.values() {
for value in squares.values() {
println!("Value {}", value);
println!("Value {}", value);
}
}
for (key, value) in squares.iter() {
for (key, value) in squares.iter() {
println!("{} => {}", key, value);
println!("{} => {}", key, value);
}
}
}</lang>
}</lang>
{{out}}
<pre>
Key three
Key two
Key one
Value 9
Value 4
Value 1
three => 9
two => 4
one => 1
</pre>


=={{header|Scala}}==
=={{header|Scala}}==