Created
November 10, 2016 21:37
-
-
Save chespinoza/0b1f351c41e1c2b8597f6ec29e933151 to your computer and use it in GitHub Desktop.
Rust Array & Vector Iteration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let v = vec![1, 2, 3, 4, 5]; | |
for u in v { | |
println!("{}", u); | |
} | |
let a = [1, 2, 3, 4, 5]; | |
for u in 1..a.len() { | |
println!("{}", u); | |
} | |
let a = ['a', 'b', 'c', 'd', 'e']; | |
for u in a.iter() { | |
println!("{}", u); | |
} | |
let a = [100, 101, 102, 103, 104]; | |
for (i, j) in a.iter().enumerate() { | |
println!("Index:{} Value:{}", i, j); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment