C++ Loops

Sometimes it is necessary to execute some statements multiple times in a program; C++ loops execute a block of statements a certain number of times until a condition is met. In this tutorial, you will learn how to use various looping statements in C++.



What are Loops in C++?

Some situations may arise during programming where the programmer needs to execute a block of code multiple times (sometimes with slight changes). Generally, statements in C++ get executed sequentially (one statement followed by another). C++ provides statements for several control structures and iteration capability, allowing programmers to execute a statement or group of statements multiple times.

C++ supports the following types of loops:

All are slightly different and provide loops for use in different situations.

Figure - Flowchart of Looping:

C++ Loop Control Statements

Loop control statements change the normal sequence of execution of the loop.

Statement Syntax Description
break statement break; It terminates the loop or switch statement.
continue statement continue; It suspends the execution of the current loop iteration and transfers control to the loop for the next iteration.
goto statement goto labelName;
labelName: statement;
It transfers the current program execution sequence to some other part of the program.


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram

Keep W3schools Growing with Your Support!
❤️ Support W3schools