Java - Decision Control and looping statement - While Tutorial
The Java, while loop is used When you exactly don’t know how many times loop, should be executed.the loop execution will automatically stop when the condition is false
public class WhileLoop {
public static void main(String[] args) {
int i=1;
while(i<=5){
System.out.println("Hello");
i++;
}
}
}
Program Explanation
In this, the condition will check first, if a true statement will be executed.
While loop doesn’t do increment/decrement of a variable in the condition itself,
Without increment/decrement, it will go into an unlimited loop.