Skip to content

Commit 2734c6c

Browse files
authored
Merge pull request #1744 from heartbeast42/patch-1
Update while_let.md: address inconsistent use of fn main between 2 co…
2 parents 0be3630 + cc57675 commit 2734c6c

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

src/flow_control/while_let.md

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,24 @@ loop {
3131
Using `while let` makes this sequence much nicer:
3232

3333
```rust,editable
34-
fn main() {
35-
// Make `optional` of type `Option<i32>`
36-
let mut optional = Some(0);
37-
38-
// This reads: "while `let` destructures `optional` into
39-
// `Some(i)`, evaluate the block (`{}`). Else `break`.
40-
while let Some(i) = optional {
41-
if i > 9 {
42-
println!("Greater than 9, quit!");
43-
optional = None;
44-
} else {
45-
println!("`i` is `{:?}`. Try again.", i);
46-
optional = Some(i + 1);
47-
}
48-
// ^ Less rightward drift and doesn't require
49-
// explicitly handling the failing case.
34+
// Make `optional` of type `Option<i32>`
35+
let mut optional = Some(0);
36+
37+
// This reads: "while `let` destructures `optional` into
38+
// `Some(i)`, evaluate the block (`{}`). Else `break`.
39+
while let Some(i) = optional {
40+
if i > 9 {
41+
println!("Greater than 9, quit!");
42+
optional = None;
43+
} else {
44+
println!("`i` is `{:?}`. Try again.", i);
45+
optional = Some(i + 1);
5046
}
51-
// ^ `if let` had additional optional `else`/`else if`
52-
// clauses. `while let` does not have these.
47+
// ^ Less rightward drift and doesn't require
48+
// explicitly handling the failing case.
5349
}
50+
// ^ `if let` had additional optional `else`/`else if`
51+
// clauses. `while let` does not have these.
5452
```
5553

5654
### See also:

0 commit comments

Comments
 (0)