]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_error_codes/src/error_codes/E0267.md
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / compiler / rustc_error_codes / src / error_codes / E0267.md
1 A loop keyword (`break` or `continue`) was used inside a closure but outside of
2 any loop.
3
4 Erroneous code example:
5
6 ```compile_fail,E0267
7 let w = || { break; }; // error: `break` inside of a closure
8 ```
9
10 `break` and `continue` keywords can be used as normal inside closures as long as
11 they are also contained within a loop. To halt the execution of a closure you
12 should instead use a return statement. Example:
13
14 ```
15 let w = || {
16 for _ in 0..10 {
17 break;
18 }
19 };
20
21 w();
22 ```