Java Do While Loop

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 checks the condition.

 

Syntax

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 W3schools360
 */
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

1
2
3
4
5
6
7
8
9
10