Website For Developers

While loop in Java



While loop in Java


Syntax

while (Boolean_expression/condition)
{
//Statements in while loop
}

Boolean_expression or Condition


Example of while loop in Java

public class WhileExample {
   public static void main(String[] args) {
     int count = 0;
     while ( count < 5 ) {
       System.out.println( "count number : " + count );
       count++;
     }
   }
}

Output

count number : 0
count number : 1
count number : 2
count number : 3
count number : 4


Explanation of above example