mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-05-17 16:12:39 +02:00
As mentioned in #2478, this cleans up the code blocks when all that is needed is a trivial debug print statement. Only making changes to Day 1 morning session so that I can get feedback before proceeding with the rest of the course. --------- Co-authored-by: Eric Githinji <egithinji@google.com>
25 lines
424 B
Markdown
25 lines
424 B
Markdown
# `loop`
|
|
|
|
The [`loop` statement](https://doc.rust-lang.org/std/keyword.loop.html) just
|
|
loops forever, until a `break`.
|
|
|
|
```rust,editable
|
|
fn main() {
|
|
let mut i = 0;
|
|
loop {
|
|
i += 1;
|
|
dbg!(i);
|
|
if i > 100 {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
<details>
|
|
|
|
- The `loop` statement works like a `while true` loop. Use it for things like
|
|
servers which will serve connections forever.
|
|
|
|
</details>
|