rust/src/test/run-pass/linear-for-loop.rs

25 lines
565 B
Rust
Raw Normal View History

2010-06-23 23:03:09 -05:00
fn main() {
let x = ~[1, 2, 3];
let mut y = 0;
2012-06-30 18:19:07 -05:00
for x.each |i| { log(debug, i); y += i; }
log(debug, y);
assert (y == 6);
let s = ~"hello there";
let mut i: int = 0;
2012-06-30 18:19:07 -05:00
for str::each(s) |c| {
2011-07-27 07:19:39 -05:00
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); }
// ...
2010-06-23 23:03:09 -05:00
i += 1;
log(debug, i);
log(debug, c);
2010-06-23 23:03:09 -05:00
}
assert (i == 11);
}