Do While Loop Java Tutorial

 
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);

Program to use do while loop example in java.

/**
 * Program to use do while loop example in java.
 * @author javawithease
 */
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

Download this example.