Slide 1 / 14
The do…while loop — runs at least once
The do…while loop is different from while and for in one key way: the condition is checked AFTER the body runs.
This means the body is guaranteed to execute at least once, no matter what.
This is perfect for:
- Asking the user for input (you must ask at least once)
- Menu-driven programs (the menu must appear at least once)
- Input validation (you must attempt to read before checking if it's valid)