Sparky sayswhile loops repeat as long as a condition holds; do-while runs at least once.
while (cond) { … } checks before each iteration; do { … } while (cond) checks after, guaranteeing one run. Use them when the iteration count isn't known up front (reading until done, retrying). Always ensure the condition eventually becomes false or you get an infinite loop.
Power-ups you unlock
while checks before; do-while checks after
do-while always runs at least once
Use when the count isn’t known in advance
Ensure the condition can become false
NaN the Trickster attacks — common mistakes
Infinite loops from a condition that never flips
Off-by-one between while and do-while
Forgetting to update the loop variable
Boss battleUse a while loop to halve a number until it drops below 1.