While Loops
while checks the condition first. do ... while runs the body once before checking. Make sure the loop changes something so it can end.
Example
int i = 1;
while (i <= 3) {
System.out.println("Round " + i);
i++;
}
int n = 10;
do {
System.out.println("n is " + n);
n++;
} while (n < 10);Result
Round 1 Round 2 Round 3 n is 10
Exercise
Repeat while a condition is true.
(i < 3) { i++; }Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.