Skip to content

Instantly share code, notes, and snippets.

@Mec-iS
Created April 11, 2019 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mec-iS/345b60df326cab1e168e2abb291c4052 to your computer and use it in GitHub Desktop.
Save Mec-iS/345b60df326cab1e168e2abb291c4052 to your computer and use it in GitHub Desktop.
[RUST] labeling nested loops
/// 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