C-While


1. The while loop is a looping statement and is used to carry out looping operations.
The general form of the statement is:
while(expression) statement

2. The included statement will be executed repeatedly, as long as the value of expression is non zero i.e. as long as the expression is true.

3. This statement can be simple or compound, though it is typically a compound statement. The while loop include some feature which eventually alters the value of the expression, thus providing a stopping condition for the loop.

4. The logical expression in while is evaluated at the beginning of each pass.


for example,
writing a program to print 1 to 10 numbers in new line.


#include<stdio.h>

void main(){
	int i=1;
	while(i<=10){
		printf(" %d \n",i);
		i++;
	}
}



Output :


1
2
3
4
5
6
8
9
10


  • Print Page