Our Best Offer Ever!! Summer Special - Get 3 Courses at 24,999/- Only. Read more
Hire Talent (HR):+91-9791 444 054

General

Do While Loop Java

Do While Loop Java

Do 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:

do{
//statements to be repeated
increment/decrement
}while(i<=10);

Example:

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

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.It will run for the first time without checking the condition.

Points to Remember:

  • We can use while loop for repeated logics.
  • 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

Besant Technologies WhatsApp