In this java article, we will be looking "DO WHILE" loops in Java. DO WHILE loops provide functionality to execute a code with giving iteration condition and scale inside the loop. WHILE loops were starting with condition at beginning, DO WHILE loops starts loop without condition at beginning. That lets us enter into loop at least 1 time and then provide a condition to keep it iterating or not.
Lets look to syntax of DO WHILE loop in Java.
int x = 1;
do
{
System.out.println(x);
x++;
}while(x<5);
Lets see it in Java code example.
In above example, we declared a variable "x" and created a DO WHILE loop. DO WHILE loop executes and print each time value of "x" and increases value of "x". Remark that our WHILE condition was till "x" smaller than 5. Once it reaches it, loop ends itself.