Loops in C++

Sometimes it is necessary in the program to execute the statement several times, and C++ loops execute a block of commands a specified number of times until a condition is met. In this post, you will learn about all the looping statements of C++ along with their use.

Loops in C++

There may arise some situations during programming where programmers need to execute the block of code several times (with slight variations sometimes). In general, statements get executed sequentially with a C++ program, one statement followed by another. C++ provides statements for several control structures along with iteration/repetition capability that allows programmers to execute a statement or group of statements multiple times.

C++ supports following types of loops:
  • while loops
  • do while loops
  • for loops





All are slightly different and provides loops for different situations.

Figure – Flowchart of Looping:

akhtarbari.com

C++ Loop Control Statements

Loop control statements are used to change the normal sequence of execution of a loop.

StatementSyntaxDescription
break statementbreak;Is used to terminate loop or switch statements.
continue statementcontinue;Is used to suspend the execution of current loop iteration and transfer control to the loop for the next iteration.
goto statementgoto labelName;labelName: statement;It transfers current program execution sequence to some other part of the program.




COPY CODE SNIPPET

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

four × three =