5.5.1. The break Statement

A break statement terminates the nearest enclosing while, do while, for, or switch statement. Execution resumes at the statement immediately following the terminated statement.

A break can appear only within an iteration statement or switch statement (including inside statements or blocks nested inside such loops). A break affects only the nearest enclosing loop or switch:

string buf;while (cin >> buf && !buf.empty()) {    switch(buf[0]) {    case '-':        // process up to the first blank        for (auto it = buf.begin()+1; it != buf.end(); ++it) {              if (*it == ' ')                   break; // #1, leaves the for loop              // . . .        }        // break #1 transfers control here        //

Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.