In this java article, we will be looking while loops in Java. WHILE loops provide functionality to execute a code with giving iteration condition and scale inside the loop.
Lets look to syntax of WHILE loop in Java.
int x = 0;
while(x < 5)
{
System.out.println(x);
x++;
}
Lets see it in Java code example.
In above example, we declared a variable "x" and created a WHILE loop. WHILE loop executes a print each time and increases value of "x". Remark that our WHILE condition was till "x" smaller than 5. Once it reaches it, loop ends.