The for loop puts initialization, condition, and update all on one line. It's the loop you'll reach for when you know in advance how many times to repeat.
Here is the syntax:
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
This prints through , just like the while loop from earlier. The difference is readability. With a while loop, the initialization, condition, and update are spread across different places. With a for loop, you see all in the header.
When you read someone else's code, a for loop immediately tells you: "this repeats a known number of times." A while loop says: "this repeats until something happens." Choosing the right one makes your intent clear.