Here’s the code:
script {
fun main() {
loop {
break; // this semi here causes error
}
}
}
┌── /scripts/script.move:4:18 ───
│
4 │ break;
│ ^ Unreachable code. This statement (and any following statements) will not be executed. In some cases, this will result in unused resource values.
│
For some reason the only possible way to use break
and continue
(and return
) is without semicolon in the end, when these statements are in “open scope”.
But! It is possible to put semi after when they are paired with if
:
script {
fun main() {
loop {
if (true) break;
if (true) continue;
if (true) return;
if (true) break // also valid - but it's the last expression
}
}
}
I don’t know what to ask. Maybe if you did it on purpose? Though I should say that for me this case is not obvious and even confusing every time I use these statements.