A while loop checks a condition before each iteration. If the condition is true, the loop body runs. If it's false, the loop stops and execution continues with the next statement after the loop.
Here is the basic structure:
int count = 0;
while (count < 5) {
System.out.println(count);
count++;
}
This prints the numbers through . On each pass, Java evaluates count < 5. Once count reaches , the condition becomes false and the loop ends.
Notice that the condition is checked before the body runs. If count started at , the body would never execute at all. That "check first, run second" behavior is what defines a while loop.