Control Flow
Checkpoints
- `for` Loops Essential The most common iteration shape in Rust: `for x in expr { … }` walks every element of an iterable — a range like `0..n`, a slice like `&v`, an array, or any value with an `IntoIterator` impl. You'll see the three flavours (`for x in v`, `for x in &v`, `for x in &mut v`) and how each relates to ownership of the elements.
- `if` Expressions Essential Rust's `if` is an *expression*, not just a statement: every branch produces a value of the same type, and the whole `if`/`else` can be assigned to a binding. You'll see the difference between `if` and `if let`, why omitting `else` is allowed only when the `if` is used as a statement (returning `()`), and the idiomatic 'early return' shape `if cond { return foo; }`.
- Iterators Essential Behind every `for` loop is the `Iterator` trait — a single `fn next(&mut self) -> Option<Self::Item>` that produces values one at a time. You'll see how iterator *adapters* (`map`, `filter`, `take`, `chain`) compose lazily into pipelines, how *consumers* (`collect`, `sum`, `fold`, `for_each`) drive them, and why this style is both idiomatic and as fast as the equivalent hand-written loop.
- The `match` Expression Essential Rust's `match` expression evaluates a value against a list of patterns and runs the arm whose pattern matches. You'll see why `match` is an *expression* (it produces a value), how exhaustiveness checking guarantees you handle every variant of a sum type, and how guards (`if`) refine arms further.
- `while` and `loop` Essential Rust's unbounded looping constructs: `while cond { … }` runs while a condition holds, `loop { … }` runs forever (until you `break` out of it), and `while let pat = expr { … }` loops as long as a pattern keeps matching. You'll see why `loop` is the only loop that can produce a value (via `break value`) and the idiomatic shapes for retry loops and event loops.