While Loop

The Java while loop is used to iterate a part of the program several times. If the number of iteration is not fixed, it is recommended to use while loop.

Syntax:

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

while loop syntax


Java Infinitive While Loop

If you pass true in the while loop, it will be infinitive while loop.

Syntax:

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