for expressions
The for expression is closely related to the while let expression. It will
automatically call into_iter() on the expression and then iterate over it:
fn main() {let v = vec![10, 20, 30];for x in v {println!("x: {x}");}for i in (0..10).step_by(2) {println!("i: {i}");}}
You can use break and continue here as usual.
Speaker Notes
- Index iteration is not a special syntax in Rust for just that case.
(0..10)is a range that implements anIteratortrait.step_byis a method that returns anotherIteratorthat skips every other element.