C++ Break Statement

Break statements provide a way to instantly jump out from the loop. After the break statement, the control is immediately shifted to a statement just below the enclosing loop or switch.

It is mostly used within for, while, do-while loops or switch statements.

Syntax: Break statement

Break;

Flow Chart: Break Statement

Example: Break statement

//break statement in C++
#include <iostream>  
using namespace std;  
int main()  
{  
    for (int i = 1; i <= 10; i++) {
        if (i == 5) {
            break;
        }
        cout << i << endl;
    }

return 0;
} 

Output

Control jumps out from the loop when i=5. Bellow is the output of the above program.

1
2
3
4