---
title: "Chapter 7: Control Flow"
description: "The 11 lessons of chapter 7: Control Flow, in teaching order."
url: "https://learnrust.net/chapter-7/"
last_updated: "2026-06-12"
---

# Chapter 7: Control Flow

- [7.1 Control flow introduction](https://learnrust.net/chapter-7/control-flow-introduction.md): Execution paths, branching, and a map of Rust's control flow tools: if, match, loops, jumps, and halts.
- [7.2 Working with if and else](https://learnrust.net/chapter-7/working-with-if-and-else.md): if-else chains versus separate ifs, flattening nested conditions, early returns, and the scope of values born inside an arm.
- [7.3 Introduction to match](https://learnrust.net/chapter-7/introduction-to-match.md): Rust's match expression: arms, patterns, the _ wildcard, or-patterns, and exhaustiveness checking as a feature.
- [7.4 loop and while](https://learnrust.net/chapter-7/loop-and-while.md): Rust's while loop, the dedicated loop keyword for infinite loops, the do-while idiom, and the unsigned countdown trap.
- [7.5 for loops and ranges](https://learnrust.net/chapter-7/for-loops-and-ranges.md): Rust's for loop over ranges: half-open and inclusive ranges, rev and step_by, and why there's no three-part C-style for.
- [7.6 break, continue, and loop labels](https://learnrust.net/chapter-7/break-continue-and-loop-labels.md): Ending loops early, skipping iterations, break-with-value from loop, and labeled breaks for nested loops.
- [7.7 Introduction to recursion](https://learnrust.net/chapter-7/introduction-to-recursion.md): Functions that call themselves: base cases, recursive cases, stack overflows, and when to prefer a loop.
- [7.8 Halting your program early](https://learnrust.net/chapter-7/halting-your-program-early.md): Exit codes, returning from main, std::process::exit, and a first proper introduction to panic!.
- [7.9 Adding a dependency: random numbers](https://learnrust.net/chapter-7/adding-a-dependency-random-numbers.md): PRNGs and seeds, crates.io, cargo add, semantic versioning, and rolling dice with the rand crate.
- [7.10 Project: the number guessing game](https://learnrust.net/chapter-7/project-number-guessing-game.md): Build the classic guessing game in Rust: loops, match on Ordering, input parsing, and your first complete program.
- [7.x Chapter 7 summary and quiz](https://learnrust.net/chapter-7/chapter-7-summary-and-quiz.md): Control flow reviewed: match, the three loops, jumps, recursion, halts, and dependencies, plus a quiz that builds real programs.

## Sitemap

See the full [sitemap](https://learnrust.net/sitemap.md) for all pages.
