Home » , , » Loop Control Statement in C Programming - " do....while "

Loop Control Statement in C Programming - " do....while "

Written By Unknown on Thursday, October 10, 2013 | 3:49 AM

Do While Statement :
The value of condition for " do.....while loop " is placed at the end of the loop.Like :

                     do
                          {
                               statement;
                           } while (condition);

Watch the program carefully : 
                            #include<stdio.h>
                            #include<conio.h>
                             main()
                                      {
                                       int i=0;
                                       do
                                      {
                                          printf(" %d ",i);
                                          i++
                                        } while (i<5);
                                        getch();
                                        }
                                           
OUTPUT :

                                               0,1,2,3,4

Program Analysis :
->                                      do
                                          {
                                          printf(" %d ",i);
                                          ................................
                                          ................................
Here the value of i will be shown first.

-> i++;
     }while(i<5);

In this step,the value of i will be increased by 1 and value will be 0 to 1 and in the mean time condition will also be checked.As i<5 so condition will be true and printf function will be executed and 1 will be shown.

-> In this way when the value of i will be 5 than the condition will be false because i can't be equal to 5 according to the condition(i<5).So the loop will end.
Share this article :

Post a Comment

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Learn Programming - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger| Distributed by Rocking Templates