After reading this do while loop topic, you will understand the do while loop flowchart, theory, and examples.
C do while loop executes statements one or more times and we can say that do while loop executes statements always at least once. This loop is suitable when we do not know how many times the loop will execute except one.
General Form (Syntax):
The syntax of do–while loop is given below,
do { statement(s); } while(expression);
As the do-while loop starts, first statement(s)inside the braces will execute and then expression gets evaluated and as evaluated condition is true then statement(s) again execute also this process repeat till expression evaluates to true condition.
do-while loop flowchart:
The flow chart of do-while loop is shown below,
Example
Program (1): To print a message “how are you” five times using do-while loop.
#include<stdio.h> #include<conio.h> void main(void) { int i=1; do { printf("How are you \n"); ++i; }while(i<=5); getch(); }
Output (1)
How are you How are you How are you How are you How are you