The While Loop



Unlike the for loop, the while loop has no initialization expression or increment /decrement expression. The while loop has loop condition which controls the execution of the loop statement.

Syntax:-

   while (loop condition)
      {
         Statement1;
         Statement2;
         ---
         ---
         ---
         Statement n;
      }
   Statement m;

If the loop condition evaluates to be true, then statement {statement1, statement2, ------, statement n} will be executed.

If the loop evaluates to be false control will go to the first statement after curly bracket.

while loop

Summary Of While Loop:

  • In while loop, the condition is tested before the loop is executed.
  • If condition is false in first attempt, then body of the loop may not be executed even once.
  • It is entry control loop statement.