@@ -569,10 +569,8 @@ loop {
569
569
This code prints out a weird sequence of numbers and stops as soon as
570
570
it finds one that can be divided by five.
571
571
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.
572
+ For more involved iteration, such as enumerating the elements of a
573
+ collection, Rust uses [ higher-order functions] ( #closures ) .
576
574
577
575
# Data structures
578
576
@@ -1395,7 +1393,6 @@ assert!(crayons.len() == 3);
1395
1393
assert!(!crayons.is_empty());
1396
1394
1397
1395
// Iterate over a vector, obtaining a pointer to each element
1398
- // (`for` is explained in the next section)
1399
1396
for crayons.each |crayon| {
1400
1397
let delicious_crayon_wax = unwrap_crayon(*crayon);
1401
1398
eat_crayon_wax(delicious_crayon_wax);
@@ -1442,10 +1439,15 @@ call_closure_with_ten(closure);
1442
1439
~~~~
1443
1440
1444
1441
Closures begin with the argument list between vertical bars and are followed by
1445
- a single expression. The types of the arguments are generally omitted,
1446
- as is the return type, because the compiler can almost always infer
1447
- them. In the rare case where the compiler needs assistance, though, the
1448
- arguments and return types may be annotated.
1442
+ a single expression. Remember that a block, ` { <expr1>; <expr2>; ... } ` , is
1443
+ considered a single expression: it evaluates to the result of the last
1444
+ expression it contains if that expression is not followed by a semicolon,
1445
+ otherwise the block evaluates to ` () ` .
1446
+
1447
+ The types of the arguments are generally omitted, as is the return type,
1448
+ because the compiler can almost always infer them. In the rare case where the
1449
+ compiler needs assistance, though, the arguments and return types may be
1450
+ annotated.
1449
1451
1450
1452
~~~~
1451
1453
let square = |x: int| -> uint { x * x as uint };
0 commit comments