E4102#
Outside of a loop.
This error occurs when using break
or continue
statements outside of a loop
construct. These control flow statements can only be used within loops.
break
is used to exit a loop earlycontinue
is used to skip to the next iteration of a loop
Using these statements outside of a loop context is invalid since there is no loop to break from or continue to the next iteration.
错误示例#
pub fn f(xs: Array[Int]) -> Int {
for i in xs {
ignore(i)
} else {
break 42
// ^^^^^^^^ Error: 'break' outside of a loop
}
}
pub fn g(x: Int) -> Int {
continue x
// ^^^^^^^^ Error: 'continue' outside of a loop
}
fn main {
let x = { break }
// ^^^^^ Error: 'break' outside of a loop
println(x)
}
建议#
To fix this error, ensure that break
and continue
are used within a loop
construct.