While Loop in C

The while construct consists of a block of code and a condition. The condition is evaluated, and if the condition is true, the code within the block is executed. This repeats until the condition becomes false. Because the while loop checks the condition before the block is executed.

The control structure is often also known as a pre-test loop. Compare this with the do while loop, which tests the condition after the loop has executed.

The while loop is also called entry control loop the following digram represent the entry control loop process.

While Loop

Syntax


while(condition)	
{
	statement;
}						
							

Example


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

void main()
{
	int i;
	clrscr();
	
	i=1;
	while(i<=10)
	{
		printf("\n%d",i);
		i++;
	}
	getch();
}
							
Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!