]> git.proxmox.com Git - rustc.git/blob - src/librustc_error_codes/error_codes/E0571.md
New upstream version 1.41.1+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0571.md
1 A `break` statement with an argument appeared in a non-`loop` loop.
2
3 Example of erroneous code:
4
5 ```compile_fail,E0571
6 # let mut i = 1;
7 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
8 let result = while true {
9 if satisfied(i) {
10 break 2*i; // error: `break` with value from a `while` loop
11 }
12 i += 1;
13 };
14 ```
15
16 The `break` statement can take an argument (which will be the value of the loop
17 expression if the `break` statement is executed) in `loop` loops, but not
18 `for`, `while`, or `while let` loops.
19
20 Make sure `break value;` statements only occur in `loop` loops:
21
22 ```
23 # let mut i = 1;
24 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
25 let result = loop { // ok!
26 if satisfied(i) {
27 break 2*i;
28 }
29 i += 1;
30 };
31 ```