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