Auto merge of #30169 - shepmaster:for-loop-into-iterator, r=steveklabnik

This commit is contained in:
bors 2015-12-03 04:34:43 +00:00
commit a2f58f3644

View file

@ -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,