]> git.lizzy.rs Git - rust.git/blob - tests/ui/for-loop-while/break.rs
Rollup merge of #106766 - GuillaumeGomez:rm-stripper-dead-code, r=notriddle
[rust.git] / tests / ui / for-loop-while / break.rs
1 // run-pass
2
3 pub fn main() {
4     let mut i = 0;
5     while i < 20 { i += 1; if i == 10 { break; } }
6     assert_eq!(i, 10);
7     loop { i += 1; if i == 20 { break; } }
8     assert_eq!(i, 20);
9     let xs = [1, 2, 3, 4, 5, 6];
10     for x in &xs {
11         if *x == 3 { break; } assert!((*x <= 3));
12     }
13     i = 0;
14     while i < 10 { i += 1; if i % 2 == 0 { continue; } assert!((i % 2 != 0)); }
15     i = 0;
16     loop {
17         i += 1; if i % 2 == 0 { continue; } assert!((i % 2 != 0));
18         if i >= 10 { break; }
19     }
20     let ys = vec![1, 2, 3, 4, 5, 6];
21     for x in &ys {
22         if *x % 2 == 0 { continue; }
23         assert!((*x % 2 != 0));
24     }
25 }