通过例子学习Rust

8.1 嵌套和标签

在嵌套的内层循环里,也可以breakcontinue外层循环。这种情况下,循环语句开头应当设定标签(例如'label),并且在breakcontinue语句后面带上相应的标签。

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