Why this fires¶
The values carried by reachable exits do not agree with the result type of a
loop expression. A bare break contributes void, so it cannot exit a loop
that is expected to produce a non-void value.
fn answer() -> int {
loop {
if ready() { break 42 }
break // error[TE229]: expected int, found void
}
}Fix it¶
Give every reachable break targeting that loop a compatible value, or use the loop only for control flow when it should not produce a result.
See also¶
TE228— a break value targetswhileorfor.