Skip to content

Commit

Permalink
Rollup merge of rust-lang#25291 - johannhof:let-expressions-example, …
Browse files Browse the repository at this point in the history
…r=steveklabnik

Maybe it's me, but I really needed an example to understand if let and refutable statements.
Playpen: http://is.gd/mjX3Gf

Let me know if the variable names are too, uh, culinary.
  • Loading branch information
Manishearth committed May 11, 2015
2 parents bd764db + 6a19046 commit 40bb7fc
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3072,6 +3072,20 @@ of a condition expression it expects a refutable let statement. If the value of
expression on the right hand side of the let statement matches the pattern, the corresponding
block will execute, otherwise flow proceeds to the first `else` block that follows.

```
let dish = ("Ham", "Eggs");
// this body will be skipped because the pattern is refuted
if let ("Bacon", b) = dish {
println!("Bacon is served with {}", b);
}
// this body will execute
if let ("Ham", b) = dish {
println!("Ham is served with {}", b);
}
```

### While let loops

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

0 comments on commit 40bb7fc

Please sign in to comment.