while checks before the body and can run zero times. do while checks afterward and runs at least once. Update a value involved in the condition so that the loop can finish.
Read the example
The complete program appears below. Read it first, predict the output, then run it.
Expected output
3
2
1
Finished
Practise
Start remaining at zero. Explain why only the do-while body prints.
Common mistake
Forgetting the decrement can create an infinite loop. The do-while statement requires a final semicolon.