- Learning Rust
- Paul Johnson Vesa Kaihlavirta
- 77字
- 2021-07-02 23:07:24
The while condition
The while condition extends the loop with a condition, as you will see in the following code snippet:
while (condition) { // do something }
Let's take a look at the following example:
fn main() { let mut done = 0u32; while done != 32 { println!("done = {}", done); done += 1; } }
The preceding code will output done = 0 to done = 31. The loop terminates when done equals 32.
推薦閱讀