C While Loop

The while is an entry control loop statement. The test condition is evaluated, if the condition is true, then the body of loop is executed. After execution of the body the test condition is once again evaluated and if it is true, the body is executed once again. This process of repeated execution of the body continues until the test condition finally becomes false and the control is transferred out of the loop. On exit, the program continues with the statement immediately after the loop.

Syntax of C While Loop:-

while(test condition)

{

body of the loop

}

 

  Example of C While Loop:-

 

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

Result :-

 

C Language while loop

 

   C While Loop Example :-

 

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

Result :-

C Language while loop

 





Follow Us

Contact Us

tutorialworldin@yahoo.com

Back to Top