Rust嵌套和标签

嵌套和标签

外循环可以使用break或continue,当在处理嵌套循环时。在这种情况, 循环必须用一些被注解:'label, 标签必须被传递给 break/continue语句.
 

#![allow(unreachable_code)]

fn main() {
    'outer: loop {
        println!("Entered the outer loop");

        'inner: loop {
            println!("Entered the inner loop");

            // This would break only the inner loop
            //break;

            // This breaks the outer loop
            break 'outer;
        }

        println!("This point will never be reached");
    }

    println!("Exited the outer loop");
}

        原文作者:Rust教程
        原文地址: https://www.yiibai.com/rust/flow_control_loop_nested.html
        本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
    点赞