E0501: Continue outside loop
| Code | Category | Stability |
|---|---|---|
E0501 | Control flow | Permanent |
Explanation
A continue expression skips the rest of the current iteration of the innermost enclosing loop or while loop. Outside a loop there is no next iteration to begin, so Rue rejects the expression.
Likely cause
A continue was placed in a function, conditional, or other block that is not nested inside a loop. Move it into the loop whose iteration should be skipped, or use another control-flow construct when execution should leave the function or conditional.
Examples
Continue from a function body
fn main() -> i32 {
continue;
0
}
Continue an enclosing loop
fn main() -> i32 {
let mut value = 0;
while value < 1 {
value = value + 1;
continue;
}
value
}