Created
April 11, 2019 13:13
-
-
Save Mec-iS/345b60df326cab1e168e2abb291c4052 to your computer and use it in GitHub Desktop.
[RUST] labeling nested loops
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Taken from "Programming Rust" by Jim Blandy and Jason Orendorff | |
// A loop can be labeled with a lifetime. In the following example, 'search: is a label for | |
// the outer for loop. Thus break 'search exits that loop, not the inner loop. | |
'search: | |
for room in apartment { | |
for spot in room.hiding_spots() { | |
if spot.contains(keys) { | |
println!("Your keys are {} in the {}.", spot, room); | |
break 'search; | |
} | |
} | |
} | |
// Labels can also be used with continue . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment