aboutsummaryrefslogtreecommitdiff
path: root/src/test/run-pass/linear-for-loop.rs
blob: 4312aea86d82cd2a6fa8beee2d9a3e310cfef127 (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
36
37
38
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 == u8('h'));
    }
    if (i == 1) {
      check (c == u8('e'));
    }
    if (i == 2) {
      check (c == u8('l'));
    }
    if (i == 3) {
      check (c == u8('l'));
    }
    if (i == 4) {
      check (c == u8('o'));
    }
    // ...
    if (i == 12) {
      check (c == u8(0));
    }
    i += 1;
    log i;
    log c;
  }
  check(i == 12);
}