Free course · Lesson 2 of 5
Control Flow: Conditions & Loops
In this lesson you will
- Choose between actions with if/elif/else
- Repeat work with for loops
Programs make decisions with if / elif / else, and repeat work
with for and while loops. Mastering these two tools lets you process any
amount of data without writing repetitive code.
for item in collection:loops over a list, string, or range directly.while condition:repeats until a condition becomes false.- Comparison operators (
==,!=,>,<) and boolean operators (and,or,not) build conditions. breakexits a loop early;continueskips to the next iteration.
💡 Practical Skill: Loops and conditions are the backbone of every automation script — from validating a batch of registration forms to generating a weekly attendance summary.
attendance = [18, 15, 20, 9, 17, 12, 20] # classes attended out of 20total_classes = 20 for i, classes_attended in enumerate(attendance, start=1): rate = classes_attended / total_classes * 100 if rate >= 80: status = "Eligible for certificate" elif rate >= 60: status = "Needs make-up session" else: status = "At risk — contact student" print(f"Student {i}: {rate:.0f}% attendance — {status}")
Practice exercise
Given the attendance list in the example, print how many learners are eligible for a certificate.
Key takeaways
- Conditions are checked top to bottom; the first True branch runs
- Loops process every item in a list without repeating code
- Always test boundary values such as 59, 60 and 80
Free self-study lesson — no certificate. For the full instructor-led program, see registration options.