The do-while loop is a control flow statement in Java that repeatedly runs a block of code if a particular condition is met. Because the condition is tested at the end of the loop, the do-while loop ensures that the block of code is performed at least once, which sets it apart from other loops (such as for and while).
Syntax :
do {
// statements
} while(condition);
First, do body statements are executed then the condition will check. If the condition is true then again execute the do body statements. This process is repeated until the condition is false. In do-while loop if the first conditon will false. If the first condition of the do-while loop is false, the do body code will still be executed once
Flow Chart:
Example:
/*** Java do-While Loop Example*/public class JavaExample {public static void main(String[] args) {int i= 0;do{System.out.println("Do While Work Here : " +i);i=i+1;}while(i<10); // Condition Work Here}}
Output:
Do WHile Work Here : 1Do WHile Work Here : 2Do WHile Work Here : 3Do WHile Work Here : 4Do WHile Work Here : 5Do WHile Work Here : 6Do WHile Work Here : 7Do WHile Work Here : 8Do WHile Work Here : 9