After reading this C while loop topic, you will understand the while loop flowchart, theory, and examples.
C while loop executes statements as long as expression evaluates to true condition and when the expression evaluates false condition the while loop gets terminate.
General Form (Syntax):
The syntax of while loop is given below,
while(expression) { statement(s); }
As the while loop starts, expression gets evaluated and as the evaluated condition is true then the statement(s) inside the braces (i.e. {}) will execute.
while loop flowchart:
The flow chart of while loop is given below,
Example:
Program (1): To print a message “how are you” five times using while loop.
#include<stdio.h> #include<conio.h> void main(void) { int i=1; while(i<=5) { printf("How are you \n"); ++i; } getch(); }
Output (1)
How are you How are you How are you How are you How are you