Why this chapter matters
Control flow is the foundation of every script because it decides which operations run, when they run, and how many times.
What you will learn
- Write and evaluate simple Python expressions with correct types.
- Use if, elif, and else blocks to encode decision rules.
- Choose for and while loops based on the shape of the task.
Lessons in this chapter
- Values, variables, and expressionsCreate variables and predict expression results.
- Conditionals with if and elifBuild decision trees that are complete and non-overlapping.
- Looping with for and whileIterate through collections and state-driven conditions.
- Guide: basics and control flowApply fundamentals to classify and validate records. Read the full guide →
Study task
Write a script that loops through order records and assigns each order one status: shipped, pending, or exception.
Chapter checkpoint
When should you choose a for loop instead of a while loop?
Use a for loop when iterating over a known collection or range. Use a while loop when repetition depends on a changing condition.