循环控制
Rust 中有三个循环关键字:while
、loop
和 for
:
while
The while keyword works much like in other languages, executing the loop body as long as the condition is true.
fn main() {
let mut x = 200;
while x >= 10 {
x = x / 2;
}
println!("Final x: {x}");
}
Rust 中有三个循环关键字:while
、loop
和 for
:
The while keyword works much like in other languages, executing the loop body as long as the condition is true.
fn main() {
let mut x = 200;
while x >= 10 {
x = x / 2;
}
println!("Final x: {x}");
}
本文档使用 BookStack 构建