Slide 1 / 16
Why do we need loops?
Imagine printing "Hello World" 100 times. Without loops, you'd write cout << "Hello World"; 100 times.
Loops let a block of code repeat automatically as many times as needed — saving you from repetition and making programs far more powerful.
Two main families:
- Counter-controlled — repeats a fixed number of times (use
for) - Condition-controlled — repeats until something changes (use
while/do-while)