Do While Loop

Do while loop executes group of Java statements as long as the boolean condition evaluates to true.

It is possible that the statement block associated with While loop never get executed because While loop tests the boolean condition before executing the block of statements associated with it.

In Java programming, sometime it's necessary to execute the block of statements at least once before evaluating the boolean condition. Do while loop is similar to the While loop, but it evaluates the boolean condition after executing the block of the statement.

Do While loop syntax

do{

;

}while();

Block of statements is any valid Java code. Boolean condition is any valid Java expression that evaluates to boolean value. Braces are options if there is only one statement to be executed.

Do While Loop

26 Comments

    • import java.util.Scanner;
      public class input
      {
      public static void main(String args[])
      {
      Scanner in=new Scanner(System.in);
      int a,b,c,d,e;
      S.O.P(“Enter all numbers:”);
      a=in.nextInt();
      b=in.nextInt();
      c=in.nextInt();
      d=in.nextInt();
      e=in.nextInt();
      if(a>b&&a>c&&a>d&&a>e){
      S.O.P(“a is greater”);
      }
      if(b>a&&b>c&&b>d&&b>e){
      SOP(“b is greater”);
      }
      if(c>a&&c>b&&c>d&&c>e){
      SOP(“c is greater”);
      }
      if(d>a&&d>b&&d>c&&d>e){
      SOP(“d is greater”);
      }
      if(e>a&&e>b&&e>c&&e>d){
      SOP(“e is greater”);
      }
      else{
      SOP(“numbers are identical”);
      }
      }

  • Create a program that will print a series of numbers based on what was entered by the user.
    ex:
    Sample output
    1
    2
    3
    4
    Done

  • guys.. will you help me to create a program ..
    in that program you can see the switch statement,do while loop and if else !!
    thank you for reading.. this is my project ..
    thank you guys.. for help me!! muah!!!

    • int z = 1;

      switch(z)

      {

      case 0 :

      {

      System.out.println(“zero”);

      break ;

      }

      case 1 :

      {

      int x = z ;

      do

      {

      System.out.println(x);

      if(x==0)

      {

      System.out.println(“error”);

      break ;

      }

      else

      {

      x ++ ;

      }

      }

      while(x<=5);

      break ;

      }

      default :

      {

      System.out.println(z+” is > 1″);

      break ;

      }

      }

  • can I ask how to loop a java with choices like a, b , c, d and each letter has their own method that will only appear when selected Im asking is how to loop it when the process of the selected is finish how will it go back to choosing in the choices again

Sponsors

Facebook Fans

Online Shopping – Flipkart