Nesting and labels

It’s possible to break or continue outer loops when dealing with nested
loops. In these cases, the loops must be annotated with some 'label, and the
label must be passed to the break/continue statement.

  1. #![allow(unreachable_code)]
  2. fn main() {
  3. 'outer: loop {
  4. println!("Entered the outer loop");
  5. 'inner: loop {
  6. println!("Entered the inner loop");
  7. // This would break only the inner loop
  8. //break;
  9. // This breaks the outer loop
  10. break 'outer;
  11. }
  12. println!("This point will never be reached");
  13. }
  14. println!("Exited the outer loop");
  15. }