Loops In C++


Loops In C++


    By now we've just seen programs that are capable of making decisions based n conditions provided to them.But a dark part of these programs is each statement of these programs is executed only once.But in real life we come along many circumstances when we need to execute the program or a piece of it some number of times. According to what we have learnt till now, this task can be completed by writing the code number of times or by running the program again and again. Either way we choose, we only end up completing the task with a lot of efforts.
    So, do we have any choice? Is there any way which can comfort us from both, typing efforts and wastage of precious time? Answer is YES, we do have a choice and this choice is to create a 'Loop'.

What Exactly Creating Loop Is ?

    Loop is a technique that helps us to execute part of our code repeatedly. There are two options we can choose to create our loop with. First is to define a fix number of times our loop should be executed, say 5 times for example. Another option is to execute the loop until a desired condition is satisfied.For example executing a part of code until value of a variable becomes 20.

Types Of Loops

There are three types of loops :
  • for loop
  • while loop
  • do-while loop.
Lets take them down one be one.

<<Multiple Statements Under if-else                      Home                                          for Loop>>

No comments:

Post a Comment