Skip to content

Commit 6dc57f4

Browse files
authored
Clarify first matching arm and all possible values
The point that the first matching arm is evaluated must be made in the text. Prompt the user to add `13` to the list of primes to demonstrate this in action. The importance of the catch-all expression `_` would be more clear once the user tries commenting it out.
1 parent 10a3a86 commit 6dc57f4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/flow_control/match.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# match
22

33
Rust provides pattern matching via the `match` keyword, which can be used like
4-
a C `switch`.
4+
a C `switch`. The first matching arm is evaluated and all possible values must be
5+
covered.
56

67
```rust,editable
78
fn main() {
@@ -14,10 +15,12 @@ fn main() {
1415
1 => println!("One!"),
1516
// Match several values
1617
2 | 3 | 5 | 7 | 11 => println!("This is a prime"),
18+
// TODO ^ Try adding 13 to the list of prime values
1719
// Match an inclusive range
1820
13..=19 => println!("A teen"),
1921
// Handle the rest of cases
2022
_ => println!("Ain't special"),
23+
// TODO ^ Try commenting out this catch-all arm
2124
}
2225
2326
let boolean = true;

0 commit comments

Comments
 (0)