Shifted focus of while-let example per review.
This commit is contained in:
parent
465a5cb194
commit
797a0bd1c1
1 changed files with 5 additions and 6 deletions
|
|
@ -61,10 +61,10 @@ In a similar fashion, `while let` can be used when you want to conditionally
|
|||
loop as long as a value matches a certain pattern. It turns code like this:
|
||||
|
||||
```rust
|
||||
# let option: Option<i32> = None;
|
||||
let mut v = vec![1, 3, 5, 7, 11];
|
||||
loop {
|
||||
match option {
|
||||
Some(x) => println!("{}", x),
|
||||
match v.pop() {
|
||||
Some(x) => println!("{}", x),
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
|
|
@ -73,9 +73,8 @@ loop {
|
|||
Into code like this:
|
||||
|
||||
```rust
|
||||
let v: vec![1, 3, 5, 7, 11, ];
|
||||
let mut iter: v.iter();
|
||||
while let Some(x) = iter.next() {
|
||||
let mut v = vec![1, 3, 5, 7, 11];
|
||||
while let Some(x) = v.pop() {
|
||||
println!("{}", x);
|
||||
}
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue