Java - Decision Control and looping statement - do-while Tutorial
In the while loop condition will check first, then only it will execute the statement.
But in the do-while loop condition will check afterward the statement is executed.
Hence in the do-while loop at least one time, the statement is executed.
public class DoWhileLoop {
public static void main(String[] args) {
int i=1;
do{
System.out.println("Hello");
i++;
}
while(i<5);
}
}
In this example, at least one time is statement executed, while the condition is false
public class DoWhileLoop {
public static void main(String[] args) {
int i=1;
do{
System.out.println("Hello");
i++;
}
while(i>5);
}
}