Java – Do while loop

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:

Output :

Value: 0

Value: 1

Value: 2

Value: 3

Value: 4

Value: 5

PREV     NEXT




Like it? Please Spread the word!