mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-03-22 06:51:58 +02:00
Update for-expressions.md (#238)
If we are introducing `for` loops, I think it is beneficial to show a very basic `for i=0; i < 10; i+=2` too.
This commit is contained in:
parent
581f5a4008
commit
66509f2f3e
@ -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.
|
||||
|
||||
<details>
|
||||
|
||||
* 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.
|
||||
|
||||
</details>
|
||||
|
Loading…
x
Reference in New Issue
Block a user