Guided Notes

Loops

while, do-while, and for loops; break and continue; nested loops; and avoiding infinite and off-by-one errors.

Three loops

Slide 1 / 5
LoopChecks conditionUse when
while (cond) { }Before each roundRepeat while something is true
do { } while (cond);After each roundBody must run at least once (menus, input)
for (init; cond; step) { }Before each roundCounting a known number of times
← Conditions: if, else & switch