fix: named loop example print

pull/73/head
RXDA 4 years ago
parent 002d58311d
commit 196e06ed96
No known key found for this signature in database
GPG Key ID: 8C3032E75317C10C

@ -2792,28 +2792,21 @@ fn main() {
This will print: This will print:
```text ```text
fn main() { Now entering the first loop.
let mut counter = 0; The counter is now: 1
let mut counter2 = 0; The counter is now: 2
println!("Now entering the first loop."); The counter is now: 3
The counter is now: 4
'first_loop: loop { // Give the first loop a name The counter is now: 5
counter += 1; The counter is now: 6
println!("The counter is now: {}", counter); The counter is now: 7
if counter > 9 { The counter is now: 8
// Starts a second loop inside this loop The counter is now: 9
println!("Now entering the second loop."); The counter is now: 10
Now entering the second loop.
'second_loop: loop { // now we are inside `second_loop The second counter is now: 0
println!("The second counter is now: {}", counter2); The second counter is now: 1
counter2 += 1; The second counter is now: 2
if counter2 == 3 {
break 'first_loop; // Break out of 'first_loop so we can exit the program
}
}
}
}
}
``` ```
A `while` loop is a loop that continues while something is still `true`. Each loop, Rust will check if it is still `true`. If it becomes `false`, Rust will stop the loop. A `while` loop is a loop that continues while something is still `true`. Each loop, Rust will check if it is still `true`. If it becomes `false`, Rust will stop the loop.

Loading…
Cancel
Save