The do while loop repeatedly executes a block of statements until a particular condition is true. It first executes a block of statements and then check the condition.
Syntax:
do {
//Block of statements
}while(condition); |
do {
//Block of statements
}while(condition);
Program to use do while loop example in java.
/**
* Program to use do while loop example in java.
* @author W3spoint
*/
public class DoWhileLoopExample {
static void whileLoopTest(int num){
int i = 1;
//do while loop test
do {
System.out.println(i);
i++;
}while(i<=num);
}
public static void main(String args[]){
//method call
whileLoopTest(10);
}
} |
/**
* Program to use do while loop example in java.
* @author W3spoint
*/
public class DoWhileLoopExample {
static void whileLoopTest(int num){
int i = 1;
//do while loop test
do {
System.out.println(i);
i++;
}while(i<=num);
}
public static void main(String args[]){
//method call
whileLoopTest(10);
}
}
Output: