While Loop in Java

While loop executes group of Java statements as long as the boolean condition evaluates to true.

while(<boolean condition>){
<Block of statements>;

Where <condition> is a boolean expression. Loop body is executed as long as condition is true.

Loop body may contain more than one statments. In that case it should be enclosed in a block.

Block of statements is any valid Java code. Boolean condition is any valid Java expression that evaluates to boolean value. Braces are options if there is only one statement to be executed.

While loop evaluates the boolean expression, and if it is true, it executes the block of statements. It continuously executes the block of statements until the boolean condition evaluates to false value. After that loop is terminated and statement immediately after the loop body will be executed.

class While{
public static void main(String a[])
 int i = 0;
     while(i < 5)
       System.out.println("i is : " + i);

Output :
i is : 0
i is : 1
i is : 2
i is : 3
i is : 4