Read Time:42 Second
C++ Loops are used to execute the same block of code a specified number of times or while a specified condition is true.
Very often when we write code, we want the same block of code to run over and over again in a row. Instead of adding several almost equal lines in a code we can use loops to perform a repetitive task like this.
In C++ there are mainly three different kinds of loops:
- while loop – loops through a block of code while a specified condition is true.
- do-while loop – a variant of the while loop which will always be executed at least once, even if the condition is false, because the code is executed before the condition is tested.
- for loop – loops through a block of code a specified number of times