Friday, 30 May 2014

Do-While In Java

Do-While Loop

The do-while loop always executes its body at least once,because its conditional expression is at the bottom of the loop.It repeats the statement or block of code while its controlling expression is true.It can execute the statements at least one  or more times.

Syntax of the while loop:

do
{
   //statements
}while(condition);
Each iteration of the do-while loop first execute the body of the loop and then evaluates the conditional expression.If this expression is true, then loop will repeat otherwise the loop terminates.

Flow Chart Of do-while loop:

Simple program of the while loop:

package org.modi;
public class Test
{
    public static void main(String[] args)
    {
 int i=5;
 do
 {
  System.out.println("Count " + i );
  i--;
 }while(i>0)
   }
}
OUTPUT
Count 5
Count 4
Count 3
Count 2 
Count 1


0 comments :

Post a Comment