C Exercises

May 29, 2020

While loop In C

In previous post we learnt for loop, in this post we will learn working of  while loop.
While loop is  used when you want to execute a block of code repeatedly with a checked condition before making an iteration. In simple language while loop is a entry  controlled looping statement.

    Syntax of while loop -

Syntax of while loop is shown above.

    Example program of while loop: 

void main()
 int i=1;
 printf(" Hello ");

Here, until test counter condition is true the statements within while loop will execute, that means until i is less than or equal to 10 it will print Hello. So it will print hello 10 times. When condition becomes false control will be transferred to the next line after the loop.

Above program shows the following Output:

No comments:

Post a Comment

If you have any doubts, please discuss here...