Skip to content

Commit 9b0986a

Browse files
committed
auto merge of #7001 : alco/rust/tutorial-for-loop, r=bstrie
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". --- Feel free to reword it and commit yourself if you don't like my wording.
2 parents b8cf2f8 + 83b68a2 commit 9b0986a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

doc/tutorial.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,10 @@ loop {
569569
This code prints out a weird sequence of numbers and stops as soon as
570570
it finds one that can be divided by five.
571571

572-
For more involved iteration, such as enumerating the elements of a
573-
collection, Rust uses [higher-order functions](#closures).
572+
Rust also has a `for` construct. It's different from C's `for` and it works
573+
best when iterating over collections. See the section on [closures](#closures)
574+
to find out how to use `for` and higher-order functions for enumerating
575+
elements of a collection.
574576

575577
# Data structures
576578

@@ -1393,6 +1395,7 @@ assert!(crayons.len() == 3);
13931395
assert!(!crayons.is_empty());
13941396
13951397
// Iterate over a vector, obtaining a pointer to each element
1398+
// (`for` is explained in the next section)
13961399
for crayons.each |crayon| {
13971400
let delicious_crayon_wax = unwrap_crayon(*crayon);
13981401
eat_crayon_wax(delicious_crayon_wax);

0 commit comments

Comments
 (0)