break Statement

The break statement, when executed in a while, for, do...while or switch statement, causes immediate exit from that statement. Program execution continues with the next statement. Common uses of the break statement are to escape early from a loop or to skip the remainder of a switch statement. Figure 5.13 demonstrates the break statement (line 13) exiting a for repetition statement.

 1   // Fig. 5.13: fig05_13.cpp 2   // break statement exiting a for statement. 3   #include <iostream> 4   using namespace std; 5  6   int main() 7   { 8      unsigned int count; // control variable also used after loop terminates 9 10      for ( count = 1; count <= 10; ++count ) // loop 10 times11      {12          ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.