Skip to main content

examples of while loop in c

/*
While Loop
While studying for loop we have seen that the number of 
iterations is known beforehand, i.e. the number of times 
the loop body is needed to be executed is known to us. 
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:
We have already stated that a loop is mainly consisted of three 
statements – initialization expression, test expression, update expression.
 The syntax of the three loops – For, while and do while mainly
  differs on the placement of these three statements.

initialization expression;
while (test_expression)
{
   // statements
 
  update_expression;
}
*/


// C program to illustrate while loop 
#include <stdio.h> 

int main() 
    // initialization expression 
    int i = 1

    // test expression 
    while (i < 6
    { 
        printf"Hello World\n");    

        // update expression 
        i++; 
    } 

    return 0

Comments

Popular posts from this blog

example of typecasting in c

/*Type Casting in C Typecasting allows us to convert one data type into other. */ //simple example to cast int value into the float. #include <stdio.h>    int   main (){   float   f = ( float ) 9 / 4 ;     printf ( "f : %f \n " ,  f  );     return   0 ;   }