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: 


#include<stdio.h>
void main()
{
 int i=1;
 while(i<=10)
 {
 printf(" Hello ");
 i++;
 }
}

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...👇