for 迴圈
Rust 中有三個迴圈關鍵字:while、loop 和 for:
while
while 關鍵字的運作方式與其他語言非常相似:
fn main() {
let mut x = 200;
while x >= 10 {
x = x / 2;
}
println!("Final x: {x}");
}
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help