Control Flow
Control Flow
Tier 1, for readers who finished First Steps. Six chapters give a program the power to decide and repeat — booleans and logic, if/elif/else, while and for loops, break/continue, lists, and your first functions. The point where you start writing real programs.
Suggest an editControl Flow
So far your programs have run straight down the page, one line after another. Tier 1 adds the two powers that make a program a program: deciding (do this only if that is true) and repeating (do this for every item, or until something changes). With those, plus lists to hold many values and functions to name a piece of work, you can write genuinely useful code.
Six chapters, in order:
- Booleans, Comparisons & Logic — the True/False values that every decision rests on, and how to combine them.
- Conditionals —
if/elif/else: running code only when a condition holds. - Loops —
whileandfor: repeating work without copy-paste. - Loop Control & Patterns —
break,continue, the loopelse, and the accumulator patterns you'll reuse forever. - Lists, the Basics — storing many values in order, and changing them in place.
- Functions, the Basics — naming a reusable piece of work, with inputs and a returned result.
This tier leans on indentation — Python uses it to mark which lines belong to an if or a loop — so watch it closely from Chapter 2 on. As before, every code block with a ▶ Run button is live: predict the output, then run it and check.
📘 How to read the Intuition boxes. Each one is built in three moves:
- The mechanism — what the interpreter is actually doing.
- A concrete bite — a specific, runnable way the naive assumption fails.
- The earned rule — the decision heuristic, now justified rather than asserted, plus its cost.