Ch 7 · Loops & Iterations · C++
Topic 7 of 13 in C++ — Complete Tutorial (Beginner) — 2 lessons.
for and Range-Based for
A loop runs a block many times automatically. The classic for loop is ideal when you know how many repetitions you need, packing start, condition, and update on one line. C++ also offers the range-based for loop, which walks directly over every item in a container with no index to manage — the cleanest way to process a vector or array.
while, do-while, break & continue
The while loop repeats while a condition stays true, and you change it yourself inside the loop. do-while checks the condition after the body, so the body always runs at least once. Inside any loop, break exits immediately and continue skips to the next repetition. The golden rule: ensure the condition will eventually become false.