condition
while
do-while
01234
012
continue jumps straight back to the condition, skipping ++i. Once i reaches 2 the state stops changing, so the condition stays true forever. A loop needs its update on every path, not just the ordinary one.
continue
++i
i
Setup The loop runs three times — allegedly.
Punchline Trace the state; do not negotiate with the loop after it starts.
-1
4 7 -1 9
sum
11
20
10
19
The break fires before sum += x, so the sentinel is never added, and the loop ends before it ever reads the 9. A sentinel marks the end of the data — it is not part of the data.
break
sum += x
9
The test depends on input that does not exist yet, so the body must run once before the condition can mean anything — that is exactly do-while. A plain while would have to test height before anything was ever read into it.
height
Setup Both updates claim they are making progress toward the gate.
Punchline One is closing the distance; the other found a treadmill.
turns
<
<=
Setup Parcels keep arriving with no manifest and no final count.
Punchline One special token says "we are done," then stays out of the total.