-->

while loop


While loop

While is keyword to declare while loop.
It is used to for repetition execution of target  statement again & again until the given condition is true .
The syntax of a while loop is:

while (testExpression)
{
    statemnt // Body of while loop
}
Here, statement may be a single statement or a block of statements. The condition may be any expression, and true is any nonzero value. The loop iterates while the condition is true.

Flow chart


Note :  while is also called entry loop
        Example
                                     #include <stdio.h>

                                     void main ()
                                      {
                                          int a=1;
       
                                      /* while loop execution */
                                                 While (a<5)
                                                {
                                                     printf("value of a: %d\n", a);
                                                      a++;
                                                 }

                                          }
            Out put
             value of a: 1
             value of a: 2
            value of a: 3
            value of a: 4
            value of a: 5

No comments:

Post a Comment

Basic structure of c program