loop
- Rust provides a
loop
keyword to indicate an infinite loop. - The
break
statement can be used to exit a loop at anytime, - whereas the
continue
statement can be used to skip the rest of the iteration and start a new one.
Failed with: TOML parsing error: expected an equals, found a newline at line 1 column 6
Original markdown input:
~~~admonish info title="loop example" collapsible=tru
```rust,editable
fn main() {
let mut count = 0u32;
println!("Let's count until infinity!");
// Infinite loop
loop {
count += 1;
if count == 3 {
println!("three");
// Skip the rest of this iteration
continue;
}
println!("{}", count);
if count == 5 {
println!("OK, that's enough");
// Exit this loop
break;
}
}
}
```
~~~