Do While Loop
A do-while loop checks its condition after the body. That guarantees at least one iteration.
This shape fits menus and input prompts that must appear once before the program can decide whether to repeat.
Run once before checking
public class Main {
public static void main(String[] args) {
int unread = 0;
do {
System.out.println("Checking inbox");
} while (unread > 0);
}
}
Output:
Checking inbox
The condition is false from the start, but the inbox is checked once because the test comes after the body. A regular while loop would skip it.
The semicolon after while (condition) is required in this loop form.
Complete the do-while loop so it prints every attempt down through 1.