PREV NEXT
Java Do while loop:
JAVA – Do while loop is similar to that of the while loop except that the condition is evaluated at the end of the loop in do-while whereas in while loop, it is evaluated before entering into the loop.
The JAVA – Do while loop is executed at least once because condition is checked after loop body. The Java – Do While loop runs while a specific condition is true.
Syntax for Java Do while loop:
do
{ //statements }while(condition) |
The statements given inside the ‘do’ block are executed at least once regardless of the condition.
Example:
1 2 3 4 5 6 7 8 9 10 11 |
int i = 0; do { System.out.println(“value:”+i); i++; } while (i<6) |
Output :
Value: 0 Value: 1 Value: 2 Value: 3 Value: 4 Value: 5 |