auto merge of #8682 : adridu59/rust/master, r=cmr
This commit is contained in:
@@ -160,6 +160,18 @@ assert_eq!(sum, 57);
|
|||||||
|
|
||||||
## For loops
|
## For loops
|
||||||
|
|
||||||
|
The function `range` (or `range_inclusive`) allows to simply iterate through a given range:
|
||||||
|
|
||||||
|
~~~
|
||||||
|
for i in range(0, 5) {
|
||||||
|
printf!("%d ", i) // prints "0 1 2 3 4"
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in std::iterator::range_inclusive(0, 5) { // needs explicit import
|
||||||
|
printf!("%d ", i) // prints "0 1 2 3 4 5"
|
||||||
|
}
|
||||||
|
~~~
|
||||||
|
|
||||||
The `for` keyword can be used as sugar for iterating through any iterator:
|
The `for` keyword can be used as sugar for iterating through any iterator:
|
||||||
|
|
||||||
~~~
|
~~~
|
||||||
|
|||||||
Reference in New Issue
Block a user