Loops cause repetition in your program for certain number of times. While a condition is true this repetition continues and if the condition becomes false, the ends and the control passes to the statements in the body of loop.
In loops there is always a condition, repetition continues
only when the condition is true.
Loops are very useful in programming as if you want to print “I
am a programmer.” For 100 times the simple solution to this is to write
cout << “I am a programmer”
<< endl; //for 100 times
But isn’t its time consuming why don’t just write a one
statement that will be executed and write this for 100 times. You just need to
give the condition that the loop continues for 100 times and after 100 times it
should exit.
There are three type of loops available in C++ which are:
· for loop
· while loop
· do-while loop
Post a Comment