Name

break statement — Exits from a loop or switch statement

Synopsis

               statement := break ;

The break statement exits from the nearest enclosing loop (do, for, or while) or switch statement. Execution continues with the statement immediately following the end of the loop or switch. An error results if break is used outside of a loop or switch statement.

Example

while(std::cin >> x) {
  if (x < 0)    break;
  data.push_back(x);
}

See Also

continue, do, for, statement, switch, while, Chapter 4

Get C++ In a Nutshell 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.