break statement in c++

  • The break statement causes an immediate exit from a loop. Because the code that follows it in the loop is not executed if the break is reached, you can also sometimes avoid nesting by including a break.
  • It is possible to force an immediate exit from a loop, bypassing the loop’s conditional test, by using the break statement.
  • The break keyword causes the entire switch statement to exit.

Syntax

break;

Flow Diagram

c++ break statement

Example

#include <iostream>
using namespace std;
   int main()
    {
     int t;

     // Loops from 0 to 9, not to 100!
     for(t=0; t<100; t++)
      {
       if(t==10)
       break; cout << t << ' ';
     }
  return 0;
}

Output

 0 1 2 3 4 5 6 7 8 9