Sunday, 20 May 2012

while and do while loop in c language



Situation

We have two hotel one is charging money for first time entry and second is not charging  money for  first time for entry.
  1. Charging money is a condition to enter in the hotel for first time and anyone who can afford this can enter in the hotel.
  2. While in second case there is no charge for first time entry.  
Above both situations are applied with while and do-while. In case of while if we want to enter in loop we need to satisfied condition but in case of do-while we don't have condition for entry in loop at first time.  

while structure is 


        initialization
        while(condition)
        {
      
          your code;


         increment/decrement;
        }

do-while structure is 

        initialization
        do{



              your code ;
              increment/decrement;
         }while(condition);

Concept for  while and do-while looping is same as for loop.

Read latest blog
 


No comments:

Post a Comment