while loop in C

In while loopFirst check the condition if condition is true then control goes inside the loop body other wise goes outside the body. while loop will be repeats in clock wise direction.

The while loop in C language is used to iterate the part of program or statements many times.

Example of while loop in C

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

				do{ //code to be executed }while

				

Example:

#include<stdio.h>
#include<conio.h>

void main(){ 
int i=1; 
clrscr(); 

do{ 
printf("%d \n",i); 
i++; 
}while(i<=10); 
getch(); 
} 

Output:

1
2
3
4
5
6
7
8
9
10

				 

Infinite do while loop

do{ 

//statement

}while(1);