Only loop is an expression that can produce a value with break v; for and while may
stop before running at all, so they have no value to break with.
Wrong#
fn main() {
while true { break 1 }
}Fixed#
fn main() {
let v = loop { break 1 }
print(v)
}Common causes#
break valuein afororwhile: useloop, orfind/find_indexto search.- A
break valuewhose type doesn't match the otherbreaks of the sameloop.