C++ Loop Control Statements for beginners

0 0
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:

  1. while loop – loops through a block of code while a specified condition is true.
  2. 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.
  3. for loop – loops through a block of code a specified number of times
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %