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");

}