do-while Loop


Java loops are used to iterate a block of code multiple number of times using for, while, do while or for-in loops.

Java do while loop iterates the block of code repeatedly till it satisfies the specified condition present after the code.

This loop will execute the block of code at least once since the condition is checked after execution of code block.

Note: Don’t forget to add a semicolon (;) after the while condition.


Syntax:

do{

    //code to be executed

}while ( condition );

Example:

int i = 0;

do {
    System.out.print( i + “  ” );
} while ( i < 5 );

Output:

0 1 2 3 4