Foundation lesson for Python loops. Read theory and syntax first, then map it to a real-world repeat process.
for walks a sequence. while repeats while a condition stays true.
The body can run many times. You write it once.
A loop repeats the same step again and again, so you do not write duplicate code. You write one instruction and Python runs it multiple times.
Loops are used for printing numbers, checking every item in a list, processing files line-by-line, game updates, retries, and automation scripts.
for i in range(1, n+1): — i takes 1, 2, 3, … nwhile condition: — check first, maybe run, repeatfor cycle in range(3): rinse three times — you know the count.
while clothes_dirty: keep washing — stop when clean. Same idea in games (spawn enemies), timers, and counting scores.
Answer all questions, then click Check answers. Use this before Practice in the editor.
Q1. What is a loop for?
Q2. `for i in range(3)` repeats how many times?
Q3. What usually stops a `while` loop?
Q4. Summing 1..N is best done with…