Skip to content

Commit ea3385c

Browse files
author
Alexis Hunt
committed
Document inclusive ranges.
This provides documentation for rust-lang/rust#28237.
1 parent e843487 commit ea3385c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/flow_control/for.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,26 @@ fn main() {
2626
}
2727
```
2828

29+
Alternatively, `a..=b` can be used for a range that is inclusive on both ends.
30+
The above can be written as:
31+
32+
```rust,editable
33+
fn main() {
34+
// `n` will take the values: 1, 2, ..., 100 in each iteration
35+
for n in 1..=100 {
36+
if n % 15 == 0 {
37+
println!("fizzbuzz");
38+
} else if n % 3 == 0 {
39+
println!("fizz");
40+
} else if n % 5 == 0 {
41+
println!("buzz");
42+
} else {
43+
println!("{}", n);
44+
}
45+
}
46+
}
47+
```
48+
2949
## for and iterators
3050

3151
The `for in` construct is able to interact with an `Iterator` in several ways.

0 commit comments

Comments
 (0)