What is loop in C.?

Loops are used in programming to execute or repeat the group of statement or block of statement.

Three type loops are there in C.

What is while loop or when we use while loop.?

If you don't know number of iteration in advance. How much iteration go long.? Then go for while loop condition.

How it work.?

It execute until the condition not go false. Keep preforming iteration until condition not become false.

Syntax of while loop statement:

	
    while(condition)
    {
    statement;
    }
    

Example of while loop program:

Lets suppose you want to print the number from 1 to 10. You can't write the 10 times printf function to print the all number. It is very time consuming process. To solve this problem we use while loop condition.

	
    #include<stdio.h>
    #include<conio.h>
    
    void main()
    {
    	int i;
        
        while(i<=10)
        {
        printf(" %d \n",i);
        }
        
        getch();
    }

Output:

	
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    

Next do while condition Next for loop condition

Advertisement here

Share this Page.

Post Your Comment