Mental Model
Go through each item in the list one by one to see or change it.
Analogy: Like walking down a row of mailboxes, checking each one in order.
Index: 0 1 2 3 4 Array: [10] -> [20] -> [30] -> [40] -> [50]
Index: 0 1 2 3 4 Array: [10] -> [20] -> [30] -> [40] -> [50]
Index: 0↑ 1 2 3 4 Array: [10] -> [20] -> [30] -> [40] -> [50]
Index: 0 1↑ 2 3 4 Array: [10] -> [20] -> [30] -> [40] -> [50]
Index: 0 1 2↑ 3 4 Array: [10] -> [20] -> [30] -> [40] -> [50]
Index: 0 1 2 3↑ 4 Array: [10] -> [20] -> [30] -> [40] -> [50]
Index: 0 1 2 3 4↑ Array: [10] -> [20] -> [30] -> [40] -> [50]
Index: 0 1 2 3 4↑ Array: [10] -> [20] -> [30] -> [40] -> [50] Printed values: 10 20 30 40 50
fn main() {
let arr = [10, 20, 30, 40, 50];
for i in 0..arr.len() {
// access element at index i
println!("{}", arr[i]);
}
}for i in 0..arr.len() {println!("{}", arr[i]);for i in 0..arr.len() {
for i in 0..arr.len() {
for i in 0..5 { println!("{}", i); }arr in Rust?let arr = [10, 20, 30];
for i in (0..arr.len()).rev() {
print!("{} ", arr[i]);
}arr:let arr = [1, 2, 3];
for i in 0..arr.len() {
println!("{}", arr[i+1]);
}arr of integers, which code snippet correctly prints only the even-indexed elements (0, 2, 4, ...) of the array?Pass the test and this pattern moves unknown