Guided Notes

Loops

while, do-while, for, and range-based for loops; break and continue; nested loops; and avoiding common loop bugs.

Four loops

Slide 1 / 5
LoopUse it to
while (cond) { }Repeat while a condition holds
do { } while (cond);Run at least once — menus, input prompts
for (int i = 0; i < n; i++) { }Count a known number of times
for (auto x : container) { }Visit every element of a string, array, or vector
← Conditions: if, else & switch