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
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.