Skip to content

Commit b1c5c26

Browse files
committed
Updated "while let" example.
1 parent 1b9a13e commit b1c5c26

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/doc/book/if-let.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ if let Some(x) = option {
5858
## `while let`
5959

6060
In a similar fashion, `while let` can be used when you want to conditionally
61-
loop as long as a value matches a certain pattern. It turns code like this:
61+
loop over an iterator as long as a value matches a certain pattern. It turns
62+
code like this:
6263

6364
```rust
6465
# let option: Option<i32> = None;
@@ -73,8 +74,9 @@ loop {
7374
Into code like this:
7475

7576
```rust
76-
# let option: Option<i32> = None;
77-
while let Some(x) = option {
77+
# let v: vec![1, 3, 5, 7, 9, ];
78+
# let mut it: v.iter();
79+
while let Some(x) = it.next() {
7880
println!("{}", x);
7981
}
8082
```

0 commit comments

Comments
 (0)