Home Java Beginners do-while Loop in Java



do-while Loop in Java
Posted on: June 7, 2007 at 12:00 AM
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:

  do
  {
  statements;
  }
 
while(condition);

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);
 
 do{
  = n % 10;
  r = r * 10 + t;
  n = n / 10;
  }while (n > 0);
  System.out.println("The reverse number : " + r);
  }
}

Download The do - while Example

Related Tags for do-while Loop in Java:
javacoopprocesstimeioprocessesloopexecstateinterpreterintaiexeoocheckifconditionforexecuteignorestatementwhiletorunsseerpastproceilitlsusewiseimfirstceinnoasstaconditionsmnttrjafterestrueemallmeprostatementsdocutsamesxesoeeessatkisirhaimellpreeaandarstatrtsawiswrittenvattssamssamrocrithcondceravstafhatlsointerpretprocesprndonomonor


More Tutorials from this section

Ask Questions?    Discuss: do-while Loop in Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.