PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://github.com/jruderman/rust
Rust | 24 lines | 20 code | 3 blank | 1 comment | 19 complexity | 078daca5fb8b5a0b3fb2e9beed236e2f MD5 | raw file
 1
 2
 3fn main() {
 4    let x = ~[1, 2, 3];
 5    let mut y = 0;
 6    for x.each |i| { log(debug, i); y += i; }
 7    log(debug, y);
 8    assert (y == 6);
 9    let s = ~"hello there";
10    let mut i: int = 0;
11    for str::each(s) |c| {
12        if i == 0 { assert (c == 'h' as u8); }
13        if i == 1 { assert (c == 'e' as u8); }
14        if i == 2 { assert (c == 'l' as u8); }
15        if i == 3 { assert (c == 'l' as u8); }
16        if i == 4 { assert (c == 'o' as u8); }
17        // ...
18
19        i += 1;
20        log(debug, i);
21        log(debug, c);
22    }
23    assert (i == 11);
24}