Sometimes it is necessary for 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 chapter, you will learn about all the looping statements of C++ along with their use.
What are Loops in C++?
There may arise some situations during programming where programmers need to execute a 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.
All are slightly different and provides loops for different situations.
Figure - Flowchart of Looping:
C++ Loop Control Statements
Loop control statements are used to change the normal sequence of execution of the loop.
Statement | Syntax | Description |
---|---|---|
break statement | break; | Is used to terminate loop or switch statements. |
continue statement | continue; | Is used to suspend the execution of current loop iteration and transfer control to the loop for the next iteration. |
goto statement | goto labelName;labelName: statement; | It transfers current program execution sequence to some other part of the program. |