elibraryportal Logo

While Loops in Java

While loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. The while loop can be thought of as a repeating if statement.


Flow Chart

While Loop statement in java

How does a While loop executes?

  1. Control falls into the while loop.
  2. Jumps to Condition
  3. Condition is tested.
    • a) If Condition yields true, the flow goes into the Body.
    • b) If Condition yields false, the flow goes outside the loop
  4. The statements inside the body of the loop get executed.
  5. Updation takes place.
  6. Control flows back to Step 2.
  7. The do-while loop has ended and the flow has gone outside.

Example1: Table Print


While Loop Example in java

Example2: Java Program to Print Multiplication Table using While Loop


Multiplication Table using While Loop in java