- Loops are such block of statements that are repeatedly executed for certain number of times on the basis of specific condition.
- The statement present in the Loop body is executed repetitively until specified condition gets false as soon as condition gets false program control comes outside the loop body and the statement present immediate after the loop’s body gets executed.
- For example if we want to print counting up to 100. To do this we have to write 100 statements but using loop we can perform this operation to write 3 or 4 lines of code.
- The following diagram shows the concept of loop:
- The C++ Language supports following types of loops:
|while loop||Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body.|
|for loop||Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable.|
|do…while loop||Like a while statement, except that it tests the condition at the end of the loop body|
|nested loops||You can use one or more loop inside any another while, for or do..while loop.|