Why this matters
Stuck on a Qureo level where something has to happen "again and again"? That's a loop. Once you see how a loop counts, those levels stop being guesswork.
The idea
A loop repeats a block of code. A counting loop walks through a range of numbers and does something each time. Here, it adds each number to a running total.
Picture it
flowchart TD
A[Start: total = 0] --> B{more numbers?}
B -- yes --> C[add next number to total]
C --> B
B -- no --> D[print total]
Worked example
total = 0
for i in range(1, 6):
total += i
print(total) # 15
Your turn
Try the practice questions for this lesson: predict what a loop prints, then write one yourself.
Recap
- A loop repeats code; iteration is one pass through it.
- A counting loop uses a range and a running total.