aboutsummaryrefslogtreecommitdiff
path: root/src/test/run-pass/linear-for-loop.rs
blob: 2b517f78fe3de79a16ab62875ef29fbdc7e26a6a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
fn main() {
  auto x = vec(1,2,3);
  auto y = 0;
  for (int i in x) {
    log i;
    y += i;
  }
  log y;
  check (y == 6);

  auto s = "hello there";
  let int i = 0;
  for (u8 c in s) {
    if (i == 0) {
      check (c == ('h' as u8));
    }
    if (i == 1) {
      check (c == ('e' as u8));
    }
    if (i == 2) {
      check (c == ('l' as u8));
    }
    if (i == 3) {
      check (c == ('l' as u8));
    }
    if (i == 4) {
      check (c == ('o' as u8));
    }
    // ...
    i += 1;
    log i;
    log c;
  }
  check(i == 11);
}