Skip to content

Instantly share code, notes, and snippets.

@chespinoza
Created November 10, 2016 21:37
Show Gist options
  • Save chespinoza/0b1f351c41e1c2b8597f6ec29e933151 to your computer and use it in GitHub Desktop.
Save chespinoza/0b1f351c41e1c2b8597f6ec29e933151 to your computer and use it in GitHub Desktop.
Rust Array & Vector Iteration
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