/*
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
Post a Comment