while expressions

The while keyword works very similar to other languages:

  1. fn main() {
  2. let mut x = 10;
  3. while x != 1 {
  4. x = if x % 2 == 0 {
  5. x / 2
  6. } else {
  7. 3 * x + 1
  8. };
  9. }
  10. println!("Final x: {x}");
  11. }