循环控制

Rust 中有三个循环关键字:whileloopfor

while

The while keyword works much like in other languages, executing the loop body as long as the condition is true.

  1. fn main() {
  2. let mut x = 200;
  3. while x >= 10 {
  4. x = x / 2;
  5. }
  6. println!("Final x: {x}");
  7. }