about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRamkumar Ramachandra <artagnon@gmail.com>2013-06-06 19:23:38 +0530
committerRamkumar Ramachandra <artagnon@gmail.com>2013-06-06 19:43:16 +0530
commitdd923e3831f93c7ad8f3b872069fdeff31e522c7 (patch)
tree12fbc3d09f9697f8dc4787ded7d3806d580e24b3
parentc2cb23807507b5c9e46f9a41fb3084993476deb7 (diff)
tutorial: fix for-loop example
Although in the example function `each` works as expected with
rust-0.6 (the latest release), it fails to even compile with `incoming`
rust (see test/compile-fail/bad-for-loop-2.rs). Change the function to
return a `bool` instead of `()`: this works fine with both versions of
rust, and does not misguide potential contributors.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
-rw-r--r--doc/tutorial.md9
1 files changed, 5 insertions, 4 deletions
diff --git a/doc/tutorial.md b/doc/tutorial.md
index 14a0c6fdcfe..8caf8704e05 100644
--- a/doc/tutorial.md
+++ b/doc/tutorial.md
@@ -1613,18 +1613,19 @@ loop. Like `do`, `for` is a nice syntax for describing control flow
 with closures.  Additionally, within a `for` loop, `break`, `loop`,
 and `return` work just as they do with `while` and `loop`.
 
-Consider again our `each` function, this time improved to
-break early when the iteratee returns `false`:
+Consider again our `each` function, this time improved to return
+immediately when the iteratee returns `false`:
 
 ~~~~
-fn each(v: &[int], op: &fn(v: &int) -> bool) {
+fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool {
    let mut n = 0;
    while n < v.len() {
        if !op(&v[n]) {
-           break;
+           return false;
        }
        n += 1;
    }
+   return true;
 }
 ~~~~