diff options
| author | blake2-ppc <blake2-ppc> | 2013-08-01 04:18:19 +0200 |
|---|---|---|
| committer | blake2-ppc <blake2-ppc> | 2013-08-01 16:54:22 +0200 |
| commit | 78cde5b9fb9db91f954f7fe4afdd230de6754e54 (patch) | |
| tree | 524e26fcde0b5f86f453eac7768b4881d6f979fc /src/libstd/num | |
| parent | 7e210a8129c844e0b3aca4a28153effd0817ef41 (diff) | |
| download | rust-78cde5b9fb9db91f954f7fe4afdd230de6754e54.tar.gz rust-78cde5b9fb9db91f954f7fe4afdd230de6754e54.zip | |
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.
Diffstat (limited to 'src/libstd/num')
| -rw-r--r-- | src/libstd/num/uint.rs | 13 |
1 files changed, 6 insertions, 7 deletions
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)); } |
