while

In while loop, a condition is evaluated before processing a body of the loop. If a condition is true then and only then the body of a loop is executed.

while loops are used in situations where we do not know the exact number of iterations of loop beforehand. The loop execution is terminated on the basis of test condition.

Syntax:

while (test_expression)

{

// statements;

 update_expression;

}

Flow Diagram:


1.Write a program to Display even Number between 1 to 10.

#include<stdio.h>

void main()

{

    int i=1;

    while(i<=10)

    {

            while(i%2==0)

              {

                printf("%d\n",i);

                i++;

              }

             i++;

    }

}

Output: