Do While loop

A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.

Syntax:

The syntax of a do...while loop is:

do {
   //Statements
} while(Boolean_expression);

Example

Let's create a file with name "Dowhile.java" :

public class Dowhile {

   public static void main(String args[]){

      int x = 1;

      do {

         System.out.print("value of x : " + x );
         x++;
         System.out.print("\n");

      } while( x < 20 );

   }

}

If the Boolean expression is true, the control jumps back up to do statement, and the statements in the loop execute again. This process repeats until the Boolean expression is false.

Compile it and Run :

c:\java>javac Dowhile.java
c:\java>java Dowhile

Loading ...

Related Results :

  1. Do While loop
Note :
  • Related Posts are generally User Blog posts.
  • or Other tutorials from other networks of w3clan.com.
  • Any registered user can create related posts based on search term tags.

About the Author