Week 4 — Loops
Apr 21 – Apr 25 · 5 lessons · Labs 8, 9, 10
- 4-a The while Loop — Foundations Syntax, tracing, the two failure modes
- 4-b The for Loop and the Counter Pattern Three-part header, scope, do-something-n-times
- 4-c Accumulator, Sentinel, Choosing a Shape Running sum/max, priming read, decision tree
- 4-d Nested Loops and Rectangular Output m×n semantics, grids, triangles
- 4-e do-while, Fencepost, Debugging Re-prompt pattern, separators, bug playbook
Objectives
- Trace
while,for, anddo-whileloops on paper - Write the counter, accumulator, and sentinel patterns from English descriptions
- Choose the loop shape with the three-question decision tree
- Use nested loops to print rectangular and triangular output
- Name loop-bug symptoms (infinite, off-by-one, zero iterations) and apply the first check
- Write one-sentence invariants for counter and accumulator loops