Skip to content

Commit 770f0e9

Browse files
author
Johann Hofmann
committed
Add if let expressions example
1 parent 750f2c6 commit 770f0e9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/doc/reference.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3064,6 +3064,17 @@ of a condition expression it expects a refutable let statement. If the value of
30643064
expression on the right hand side of the let statement matches the pattern, the corresponding
30653065
block will execute, otherwise flow proceeds to the first `else` block that follows.
30663066

3067+
```
3068+
let dish = ("Ham", "Eggs");
3069+
if let ("Bacon", b) = dish { // will not execute because let is refuted
3070+
println!("Bacon is served with {}", b);
3071+
}
3072+
3073+
if let ("Ham", b) = dish { // will execute
3074+
println!("Ham is served with {}", b);
3075+
}
3076+
```
3077+
30673078
### While let loops
30683079

30693080
A `while let` loop is semantically identical to a `while` loop but in place of a

0 commit comments

Comments
 (0)