1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-07-14 01:54:50 +02:00
Files
comprehensive-rust/src/control-flow-basics/loops.md
Eric Githinji 0daab179e9 Use dbg! instead of println! in Day 1 mng session (#2652)
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>
2025-02-24 14:12:56 +00:00

25 lines
423 B
Markdown

---
minutes: 5
---
# Loops
There are three looping keywords in Rust: `while`, `loop`, and `for`:
## `while`
The
[`while` keyword](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops)
works much like in other languages, executing the loop body as long as the
condition is true.
```rust,editable
fn main() {
let mut x = 200;
while x >= 10 {
x = x / 2;
}
dbg!(x);
}
```