E0500: Break outside loop
| Code | Category | Stability |
|---|---|---|
E0500 | Control flow | Permanent |
Explanation
A break expression exits the innermost enclosing loop or while loop. Outside a loop there is no control-flow target to exit, so Rue rejects the expression instead of assigning it a destination.
Likely cause
A break was placed in a function, conditional, or other block that is not nested inside a loop, or it was intended to leave a function. Put the expression inside the loop it should exit; use return when the intended target is the enclosing function.
Examples
Break from a function body
fn main() -> i32 {
break;
0
}
Break from an enclosing loop
fn main() -> i32 {
loop {
break;
}
0
}