While Loop in C

While Loop in C

In while loop First 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.

Syntax

Assignment;
while(condition)
{
statements;
............
Increment or Decrements (++ or --);
}
Note: If while loop condition never false then loop become infinite loop.

When while loop is use ?

When we do not know about how many times loops are perform or iteration of loop is unknown.

Flow Diagram

While Loop

Example of while Loop

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

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

Output

Output:
1
2
3
4
Execution process of while loop is slower than for loop.

Comments

Popular posts from this blog

Variables,Operators and Expressions in 'C' Language

For Loop in C

Built-in Data Types: In 'C' Language