Logo

Programming-Idioms

History of Idiom 7 > diff from v94 to v95

Edit summary for version 95 by programming-idioms.org:
[Rust] +DemoURL

Version 94

2020-10-10, 19:26:48

Version 95

2020-10-21, 10:36:46

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Variables
i,x,items
Variables
i,x,items
Extra Keywords
traverse traversal
Extra Keywords
traverse traversal
Code
for (i, x) in items.iter().enumerate() {
    println!("Item {} = {}", i, x);
}
Code
for (i, x) in items.iter().enumerate() {
    println!("Item {} = {}", i, x);
}
Demo URL
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=88969b976961b1302d199e00ca741db9