嵌套和标签 - Rust By Example
Description: Rust by Example (RBE) is a collection of runnable examples that illustrate various Rust concepts and standard libraries.

## Keyboard shortcuts

Press `←` or `→` to navigate between chapters

Press `S` or `/` to search in the book

Press `?` to show this help

Press `Esc` to hide this help

# 嵌套和标签

在处理嵌套循环时，可以 `break` 或 `continue` 外层循环。这种情况下，循环必须用 `'label` 标记，并且必须将标签传递给 `break`/`continue` 语句。

    #![allow(unreachable_code, unused_labels)]

    fn main() {
        'outer: loop {
            println!("进入外层循环");

            'inner: loop {
                println!("进入内层循环");

                // 这只会中断内层循环
                //break;

                // 这会中断外层循环
                break 'outer;
            }

            println!("这一点永远不会到达");
        }

        println!("退出外层循环");
    }