diff --git a/src/control-flow/for-expressions.md b/src/control-flow/for-expressions.md index eb60704d..6b1cd17d 100644 --- a/src/control-flow/for-expressions.md +++ b/src/control-flow/for-expressions.md @@ -10,7 +10,19 @@ fn main() { 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. + +
+ +* Index iteration is not a special syntax in Rust for just that case. +* `(0..10)` is a range that implements an `Iterator` trait. +* `step_by` is a method that returns another `Iterator` that skips every other element. + +