Skip to Content

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

  1. Do{
  3.         <Block of statements>;
  5. }while(<boolean condition>);

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 Examples

Join 1000+ fellow learners! Enter your email address below: