Clarify that a for loop uses IntoIterator
This commit is contained in:
parent
88397e092e
commit
06e4b709c3
1 changed files with 7 additions and 5 deletions
|
|
@ -80,13 +80,15 @@ for var in expression {
|
|||
}
|
||||
```
|
||||
|
||||
The expression is an [iterator][iterator]. The iterator gives back a series of
|
||||
elements. Each element is one iteration of the loop. That value is then bound
|
||||
to the name `var`, which is valid for the loop body. Once the body is over, the
|
||||
next value is fetched from the iterator, and we loop another time. When there
|
||||
are no more values, the `for` loop is over.
|
||||
The expression is an item can can be converted into an [iterator] using
|
||||
[`IntoIterator`]. The iterator gives back a series of elements. Each element is
|
||||
one iteration of the loop. That value is then bound to the name `var`, which is
|
||||
valid for the loop body. Once the body is over, the next value is fetched from
|
||||
the iterator, and we loop another time. When there are no more values, the `for`
|
||||
loop is over.
|
||||
|
||||
[iterator]: iterators.html
|
||||
[`IntoIterator`]: ../std/iter/trait.IntoIterator.html
|
||||
|
||||
In our example, `0..10` is an expression that takes a start and an end position,
|
||||
and gives an iterator over those values. The upper bound is exclusive, though,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue