#E0059: keyword outside its context
break and continue work only inside a loop, yield only in a generator, await only in an async body, and self only inside a method; return, break and continue cannot leave a finally block; break value leaves only a loop or a labelled block, not while / for. Move the code into such a body, or out of the finally.
nabi
let n = 3;
if n > 2 { break; }
error[E0059]: `break` outside of a loop --> main.nabi:2:12 | 2 | if n > 2 { break; } | ^^^^^
Use break inside a loop:
nabi
for n in 0..5 {
if n > 2 { break; }
println(f"{n}");
}
0
1
2
Related: E0018 return with a value in top-level statements, E0060 let .. else that does not diverge
Found a mistake? Edit this page on GitHub. Last updated