Part 2: Decisions and loops¶
This part covers how a program chooses between paths and how it repeats work. You will compare values, branch with if, and repeat with while and for. Work through the lessons in order, because each one uses the ideas of the lessons before it.
- Booleans and comparisons: Compare values, and combine conditions with
and,or, andnot. ~15 min - if, elif, and else: Run a block only when a condition holds, and choose between several cases. ~15 min
- Repeating with while: Repeat a block while a condition holds, and update a counter so the loop ends. ~15 min
- Repeating with for and range: Loop over the numbers produced by
range, and use an accumulator to build a result. ~15 min - Leaving a loop with break and continue: Stop a loop early, or skip the rest of one round. ~15 min
- Nested loops and printed patterns: Put one loop inside another, and print grids and triangles. ~15 min