diff options
| author | Alexei Sholik <alcosholik@gmail.com> | 2013-06-08 01:24:29 +0300 |
|---|---|---|
| committer | Alexei Sholik <alcosholik@gmail.com> | 2013-06-08 03:17:56 +0300 |
| commit | 83b68a2f69471e0217422cf30d6c45ec4fe28b70 (patch) | |
| tree | 36f8fa49dc7d856a6e1345de702c36d9fdeab42b | |
| parent | b8cf2f8056d29423430b723acd70e525d1249a32 (diff) | |
| download | rust-83b68a2f69471e0217422cf30d6c45ec4fe28b70.tar.gz rust-83b68a2f69471e0217422cf30d6c45ec4fe28b70.zip | |
Mention `for` in the section on loops
The "4.3 Loops" section only describes `while` and `loop`. We then see `for` used in a code sample at the end of the "13. Vectors and strings" section, but it's explained for the first time only in the next section -- "14. Closures". It is worth mentioning it in "4.3 Loops".
| -rw-r--r-- | doc/tutorial.md | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/doc/tutorial.md b/doc/tutorial.md index 8caf8704e05..56630d0c9c6 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -569,8 +569,10 @@ loop { This code prints out a weird sequence of numbers and stops as soon as it finds one that can be divided by five. -For more involved iteration, such as enumerating the elements of a -collection, Rust uses [higher-order functions](#closures). +Rust also has a `for` construct. It's different from C's `for` and it works +best when iterating over collections. See the section on [closures](#closures) +to find out how to use `for` and higher-order functions for enumerating +elements of a collection. # Data structures @@ -1393,6 +1395,7 @@ assert!(crayons.len() == 3); assert!(!crayons.is_empty()); // Iterate over a vector, obtaining a pointer to each element +// (`for` is explained in the next section) for crayons.each |crayon| { let delicious_crayon_wax = unwrap_crayon(*crayon); eat_crayon_wax(delicious_crayon_wax); |
