rankz_VtujUdhflsoFhdgp Different between while and Do-While loop- - All type study material

Java programming

Java programming

About Me

my self - Harvendra Singh

Search This Blog

Tuesday, February 18, 2020

Different between while and Do-While loop-

Different between while and Do-While loop-

Java interation stement are for, while or do- while. These statements create what we commonly call loops.

                                 
https://Erhsmathur.blogspot.com

While loop -

  • The while loop is Java's most fundamental loop stement.
  • It repeats a stement or block while it's controlling expression is true. 
  • While (condition)  
     {
        // body of loop
      }
  • The condition can be any boolean expression.  The body of the loop will be executed as the conditional expression on is true,when condition becomes false, control passes to the next line of code immediately following the loop. 

      
      Do-while -

  • There are times when you would like to test the termination expression at the end of the rather than at the beginning. 
  • The do-while loop always executes it's body at least once, because it's conditional expression is at the button of the loop;   

  • do
          {
         // body of loop
         }
          while(condition)

  • Each iteration of the do while loop first executes the body of loop and then evaluates the conditional expression.If this expression is true, the loop will repeat otherwise, the loop terminates. As with all of Java's loop, condition must be a boolean.

    

5 comments: