← All lectures

Lecture 09 · 30 min

for Loop, break & continue

Counter-controlled repetition with the for loop, plus break and continue for altering control flow inside loops.

for loopCounter vs sentinelbreakcontinue
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)
← / → navigateF fullscreenEsc exit⌘K search