do-while loop in C

To execute a part of program or code several times, we can use do-while loop of C language.

In do while loop, statement is given before the condition, so statement or code will be executed at lease one time. In other words, we can say it is executed 1 or more times.

It is better if you have to execute the code at least once.

The syntax of do-while loop in c language is given below:

		do{ 
		//code to be executed
		}while

					

Example:


#include<stdio.h>
#include<conio.h>
void main(){ 
inti=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);