From 78cde5b9fb9db91f954f7fe4afdd230de6754e54 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Thu, 1 Aug 2013 04:18:19 +0200 Subject: std: Change `Times` trait to use `do` instead of `for` Change the former repetition:: for 5.times { } to:: do 5.times { } .times() cannot be broken with `break` or `return` anymore; for those cases, use a numerical range loop instead. --- src/libstd/num/uint.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/libstd/num') diff --git a/src/libstd/num/uint.rs b/src/libstd/num/uint.rs index 126150c0f1b..275a72d6ecc 100644 --- a/src/libstd/num/uint.rs +++ b/src/libstd/num/uint.rs @@ -97,22 +97,21 @@ pub fn iterate(lo: uint, hi: uint, it: &fn(uint) -> bool) -> bool { impl iter::Times for uint { #[inline] /// - /// A convenience form for basic iteration. Given a uint `x`, - /// `for x.times { ... }` executes the given block x times. + /// A convenience form for basic repetition. Given a uint `x`, + /// `do x.times { ... }` executes the given block x times. /// /// Equivalent to `for uint::range(0, x) |_| { ... }`. /// /// Not defined on all integer types to permit unambiguous /// use with integer literals of inferred integer-type as - /// the self-value (eg. `for 100.times { ... }`). + /// the self-value (eg. `do 100.times { ... }`). /// - fn times(&self, it: &fn() -> bool) -> bool { + fn times(&self, it: &fn()) { let mut i = *self; while i > 0 { - if !it() { return false; } + it(); i -= 1; } - return true; } } @@ -190,6 +189,6 @@ pub fn test_times() { use iter::Times; let ten = 10 as uint; let mut accum = 0; - for ten.times { accum += 1; } + do ten.times { accum += 1; } assert!((accum == 10)); } -- cgit 1.4.1-3-g733a5