Step: Loops: while and break

Loops: while and break

while True: loops forever until a break statement exits it — a common pattern when the exit condition is easier to check mid-loop than up front.

Why it matters: not every loop has a clean upfront bound; while/break handles "keep going until X happens".

Example: reading input "until the user types quit" is naturally a while True + break.

Your turn: print 1 through 5, breaking out once n exceeds 5.

Pitfall: forgetting to update the loop variable (n += 1) before looping back gives you an infinite loop.

Your code:
Expected output:
1
2
3
4
5
Step 11 of 18