Skip to content

Commit

Permalink
Document inclusive ranges as a new feature.
Browse files Browse the repository at this point in the history
This provides documentation for rust-lang/rust#28237.
  • Loading branch information
alercah committed Jan 24, 2018
1 parent db29e50 commit fa7a885
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions second-edition/src/appendix-06-newest-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,24 @@ fn main() {
assert_eq!(result, 20);
}
```

## Inclusive ranges

Previously, when a range (`..` or `...`) was used as an expression, it had to be
`..`, which is exclusive of the upper bound, while patterns had to use `...`,
which is inclusive of the upper bound. Now, `..=` is accepted as syntax for
inclusive ranges in both expression and range context:

```rust
fn main() {
for i in 0 ..= 10 {
match i {
0 ..= 5 => println!("{}: low", i),
6 ..= 10 => println!("{}: high", i),
}
}
}
```

The `...` syntax is still accepted in matches, but it is not accepted in
expressions. `..=` should be preferred.

0 comments on commit fa7a885

Please sign in to comment.