Rust循環
循環
Rust 提供了一個loop關鍵字來表示一個無限循環。
break語句可以用來退出循環,在任何時候, continue語句可用於跳過循環的剩餘部分,並開始一個新的開始。
fn main() {
let mut count = 0u32;
println!("Let's count until infinity!");
// Infinite loop
loop {
count += 1;
if count == 3 {
println!("three");
// Skip the rest of this iteration
continue;
}
println!("{}", count);
if count == 5 {
println!("OK, that's enough");
// Exit this loop
break;
}
}
}
相關參考:
Rust嵌套和標籤
0 條評論,你可以發表評論,我們會進行改進
