java / beginner
Snippet
The While Loop
The while loop repeats a block of code as long as a specified boolean condition is true. It is useful when you don't know exactly how many times to loop beforehand.
snippet.java
1
2
3
4
5
int count = 1;while (count <= 3) {System.out.println("Count: " + count);count++;}
Breakdown
1
while (count <= 3)
The loop checks if count is less than or equal to 3 before each execution.
2
System.out.println(...);
Prints the current value of count to the console.
3
count++;
Increments the count variable to eventually make the loop condition false.