]> git.lizzy.rs Git - rust.git/blob - src/test/ui/for-loop-while/linear-for-loop.rs
Auto merge of #99028 - tmiasko:inline, r=estebank
[rust.git] / src / test / ui / for-loop-while / linear-for-loop.rs
1 // run-pass
2 pub fn main() {
3     let x = vec![1, 2, 3];
4     let mut y = 0;
5     for i in &x { println!("{}", *i); y += *i; }
6     println!("{}", y);
7     assert_eq!(y, 6);
8     let s = "hello there".to_string();
9     let mut i: isize = 0;
10     for c in s.bytes() {
11         if i == 0 { assert_eq!(c, 'h' as u8); }
12         if i == 1 { assert_eq!(c, 'e' as u8); }
13         if i == 2 { assert_eq!(c, 'l' as u8); }
14         if i == 3 { assert_eq!(c, 'l' as u8); }
15         if i == 4 { assert_eq!(c, 'o' as u8); }
16         // ...
17
18         i += 1;
19         println!("{}", i);
20         println!("{}", c);
21     }
22     assert_eq!(i, 11);
23 }