java / beginner
Snippet
The While Loop
The while loop repeatedly executes a block of code as long as its boolean condition remains true. The condition is checked before every iteration.
snippet.java
1
2
3
4
5
int count = 0;while (count < 3) {System.out.println("Looping...");count = count + 1;}
Breakdown
1
while (count < 3) {
The loop continues as long as 'count' is less than 3.
2
count = count + 1;
Increments the counter to eventually break the loop condition.