Lyricdev
GitHub

LYR-SEM0147

'break' or 'continue' outside a loop

error · spec 07-statements

A 'break' or 'continue' without a label stands outside every loop of its function — including in a lambda's body inside a loop.

Explanation

break and continue act on the innermost loop of their own function. A lambda's body is a function of its own: the loop around the lambda is not its loop, since the lambda may run after the loop has ended.

Move the statement into a loop, use return to leave a lambda's body, or restructure the loop.

Wrong

fn main(): void {
    break;
}
fn main(): void {
    loop {
        break;
    }
}