do-while Loop in Java

In this section you will learn how to use the do-while statement in java.

do-while Loop in Java


In some conditions in java, you need to run some statements and processes once at least. For that you have to use the do while loop in  after that check the condition then we use the do-while loop statement. do-while loop is same as the while loop statement but while loop checks the certain condition is first and if condition is true then statements or processes are executed otherwise all the statements written under the while loop is ignored by the interpreter but do - while loop executes all the statements first at once and then check the condition if the condition is true then all the statements are also executed in second times otherwise second times ignored all the statements.

The Syntax for the do-while loop:


In this example you will see how to use the do-while loop statement. The values are already given the variable n and r in the program after that it calculate the program and its perform the its original number and its reverse number.

Here is the code of the program:-

public class DoWhile{
 public static void main(String[] args){
  int n = 12345;
  int t,r = 0;
  System.out.println("The original number : " + n);
  = n % 10;
  r = r * 10 + t;
  n = n / 10;
  }while (n > 0);
  System.out.println("The reverse number : " + r);

Download The do - while Example

Share on Google+Share on Google+

do-while Loop in Java

Posted on: June 7, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: do-while Loop in Java   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
Noor Suhadah
February 7, 2012
loop with while_for_do while

1. for 2. while 3. do while display the following for loop 1 12 123 1234
March 6, 2012
blocking username and password..

i am requesting for a code for that matter
enrique demon
April 23, 2012

its a nice program
Balaji Sankar
May 28, 2012

Please provide a step by step process of how the program s working
July 30, 2012

can you please add more examples?
aslima asim ali
September 13, 2012

actualy it is not a comment:i want to ask how to make a do while loop in java program?can you help me pls :)
Abhishek gautam
June 25, 2013
core java

nested do while loop or do while A AB ABH ABHI ABHIS what is the source code
July 26, 2013

its very nice to student
October 4, 2013

Question print multiples of 37 below 100 using do while loop