Don't let the Lockdown slow you Down - Enroll Now and Get 3 Course at 24,999/- Only. Explore Now!

General

While Loop in Java

While Loop Java

While Loop in Java

It is also part of looping in java. It provides some additional functionality to iterate loop. We can give condition and increment in statement.

Syntax:

while (condition;)
{
//statements to be repeated
increment/decrement
}

Example:

public class WhileExercise {   
       public static void main(String[] args) { 
           //Code of Java for loop 
           while(i<=10){ 
               System.out.println(i);
              i++;
           }        
          } 
       }

Here we are initializing I with 0 and giving the condition that will check if i=10 and incrementing with 1 every time it will execute loop.

Points to Remember:

  • We can use while loop for repeated logic.
  • If we do not give any parameter in for block then it is infinite loop.
  • We can initialization with user defined value, condition and increment also can be user defined.

Click Here-> Get Java Training with Real-time Projects

Scroll Up
Besant Technologies WhatsApp