elibraryportal Logo

do-while Loop in Java

do-while loop is an Exit control loop. A do-while check the condition after executing the statements or the loop body.

Syntax:

Flow Chart

Do While Loop of Java

How does a do-While loop flow executes?

  1. Control falls into the do-while loop. .
  2. The statements inside the body of the loop get executed.
  3. Updation takes place.
  4. The flow jumps to Condition
  5. Condition is tested.
    • a) If Condition yields true, goto Step 6. .
    • b) If Condition yields false, the flow goes outside the loop
  6. Flow goes back to Step 2.

Example1: Table Print

Output

DoWhile Loop of Java

Example2: We are going to enter number = 4. It Work this Program, total = 4 + 3 + 2 + 1 = 10

Output

It Work this Program, total = 4 + 3 + 2 + 1 = 10
 
DoWhile Loop of Java

Example3 : Java program to print numbers from 1 to N using do while loop.

Output

 Print N Number using DoWhile Loop in Java