Error code E0267

A loop keyword (break or continue) was used inside a closure but outside of any loop.

Erroneous code example:

let w = || { break; }; // error: `break` inside of a closure
Run

break and continue keywords can be used as normal inside closures as long as they are also contained within a loop. To halt the execution of a closure you should instead use a return statement. Example:

let w = || {
    for _ in 0..10 {
        break;
    }
};

w();
Run

Back to list of error codes