while Loop


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

Java while loop iterates the block of code repeatedly till it satisfies the specified condition. It is used when the number of iterations is not known before.


Syntax:

while ( condition )
{
    //code to be executed
}    

Example:

int i = 0;

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

Output:

0 1 2 3 4