c902eafa14
Most could use the each method, but because of the hack used to disambiguate old- and new-style loops, some had to use vec::each. (This hack will go away soon.) Issue #1619
25 lines
561 B
Rust
25 lines
561 B
Rust
|
|
|
|
fn main() {
|
|
let x = [1, 2, 3];
|
|
let mut y = 0;
|
|
for x.each {|i| log(debug, i); y += i; }
|
|
log(debug, y);
|
|
assert (y == 6);
|
|
let s = "hello there";
|
|
let mut i: int = 0;
|
|
for str::each(s) {|c|
|
|
if i == 0 { assert (c == 'h' as u8); }
|
|
if i == 1 { assert (c == 'e' as u8); }
|
|
if i == 2 { assert (c == 'l' as u8); }
|
|
if i == 3 { assert (c == 'l' as u8); }
|
|
if i == 4 { assert (c == 'o' as u8); }
|
|
// ...
|
|
|
|
i += 1;
|
|
log(debug, i);
|
|
log(debug, c);
|
|
}
|
|
assert (i == 11);
|
|
}
|