PREVIOUS
NEXT CHAPTER
do While loop
do while loop is used when you know that it is compulsory to run loop at least once.In while loop and for loop checking of condition is done at beginning of loop .But in do while loop checking is done at the end of iteration.
do While loop syntax in C
do
{
//statements;
}
while(condition);
In do while loop firstly statements are executed then condition is checked.Hence there is always at least one time execution of statements inside it..
Example:
int i=0;
do
{
printf("hiiiiiiiii");
i++;
}
while(i<=0);
In above example ,without checking any condition ,statements inside do will run.hiiii will be printed as output.i gets incremented to 1.After running 1st time ,condition is checked.If condition gets true then loop will run again otherwise do
while loop C will terminate.In above example loop will terminate after 1st run after because i became 1 after 1st run and itis not less then or equal to zero .
PREVIOUS
NEXT CHAPTER