C++ break Statement
The
break statement is used to alter the normal flow of a program. The
break statement terminates a
loop (for, while and do..while) and
switch statement instantly where it applied.
When a
break statement is applied inside
the nested loop, it only affects (breaks) the inner loop.
Syntax
C++ break Example
#include <iostream>
using namespace std;
int main() {
for (int i=0;i<10;i++)
{
cout <<i <<endl;
if (i==5)
{
break;
}
}
cout << "loop end";
return 0;
}
Output: