]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0267.md
Rollup merge of #62514 - stephaneyfx:box-ffi, r=nikomatsakis
[rust.git] / src / librustc_error_codes / error_codes / E0267.md
1 This error indicates the use of a loop keyword (`break` or `continue`) inside a
2 closure but outside of any loop. Erroneous code example:
3
4 ```compile_fail,E0267
5 let w = || { break; }; // error: `break` inside of a closure
6 ```
7
8 `break` and `continue` keywords can be used as normal inside closures as long as
9 they are also contained within a loop. To halt the execution of a closure you
10 should instead use a return statement. Example:
11
12 ```
13 let w = || {
14     for _ in 0..10 {
15         break;
16     }
17 };
18
19 w();
20 ```