logo

Do While Loop In Java


Show

A do...while loop is alike to an as a loop, except that a do...while loop is certain to perform at least one time.

Syntax

Following is the syntax of a do...while loop:

do {
   // Statements
}while(Boolean_expression);

Notice that the Boolean expression emerges at the end of the loop, so the declarations in the loop perform once before the Boolean is tested.

If the Boolean expression is true, the organize jumps back up to do a line, and the loops in the statement loop execute once more. This procedure repeats until the Boolean expression is false.

Flow Diagram

Example

public class Test {

   public static void main(String args[]) {

      for(int x = 10; x < 20; x = x + 1) {
         System.out.print("value of x : " + x );
         System.out.print("\n");
      }
   }
}

This will produce the following result:

Output

value of x : 10
value of x : 11
value of x : 12
value of x : 13
value of x : 14
value of x : 15
value of x : 16
value of x : 17
value of x : 18
value of x : 19

Here at Intellinuts, we have created a complete Java tutorial for Beginners to get started in Java.