Decisions and repetition
Direct a program with conditions, process collections with loops, and build readable comprehensions.
Collections (lists, dicts, sets) and comparison operators.
Express complex rules with conditionals, process collections efficiently with loops, and repeat work with clear stopping conditions and proper iteration patterns.
Read in order, or jump to what you need.
Every lesson builds on the one before it. Open any lesson to read the explanation, run the examples, and try the practice challenges.
- 03.01Conditions and boolean logic4 min
Translate rules into precise tests and choose branches that handle boundary cases correctly.
- 03.02Pattern matching with match and case4 min
Express branching rules by the shape of data, add guards for conditions, and keep captures readable.
- 03.03For loops and range4 min
Process each item in a sequence and build useful totals without duplicating instructions.
- 03.04While loops and loop control4 min
Repeat while a condition holds, prove that a loop can finish, and use break and continue carefully.
- 03.05Loop drills and patterns4 min
Build fluency with nested loops, accumulators, prime tests, and formatted output by writing the classic loop exercises properly.
- 03.06Comprehensions4 min
Build new collections with concise transformations and filters while keeping the rule readable.
Ready to move on?
Process a collection of records, handle a boundary value (first/last item, empty collection), and explain exactly why your loop terminates without infinite loops.
Open the module self-check