Syntax of do while loop
initialization;
do
{
// statements
} while(condition);
In do while loop first iteration always be executed even the condition is false.If you think
do-while
as English like language word, it says- first do then check condition given in while.
Example:
condition is false at first iteration:
#include<stdio.h>
int main()
{
int i=10;
do
{
printf(&quot;I am inside do-while() loopn&quot;);
i++;
}while(i&gt;12);
}
OUTPUT
I am inside do-while() loop
condition is true at first iteration:
#include<stdio.h>
int main()
{
int i=10;
do
{
printf(&quot;I am inside do-while() loopn&quot;);
i++;
}while(i>12);
}
OUTPUT
I am inside do-while() loop
I am inside do-while() loop
Next Previous