6 Statements [stmt.stmt]

6.6 Jump statements [stmt.jump]

Jump statements unconditionally transfer control.

jump-statement:
    break ;
    continue ;
    return expressionopt ;
    return braced-init-list ;
    goto identifier ;

On exit from a scope (however accomplished), objects with automatic storage duration ([basic.stc.auto]) that have been constructed in that scope are destroyed in the reverse order of their construction. [ Note: For temporaries, see [class.temporary].  — end note ] Transfer out of a loop, out of a block, or back past an initialized variable with automatic storage duration involves the destruction of objects with automatic storage duration that are in scope at the point transferred from but not at the point transferred to. (See [stmt.dcl] for transfers into blocks). [ Note: However, the program can be terminated (by calling std::exit() or std::abort() ([support.start.term]), for example) without destroying class objects with automatic storage duration.  — end note ]

6.6.1 The break statement [stmt.break]

The break statement shall occur only in an iteration-statement or a switch statement and causes termination of the smallest enclosing iteration-statement or switch statement; control passes to the statement following the terminated statement, if any.

6.6.2 The continue statement [stmt.cont]

The continue statement shall occur only in an iteration-statement and causes control to pass to the loop-continuation portion of the smallest enclosing iteration-statement, that is, to the end of the loop. More precisely, in each of the statements

while (foo) {
  {
    // ...
  }
contin: ;
}
do {
  {
    // ...
  }
contin: ;
} while (foo);
for (;;) {
  {
    // ...
  }
contin: ;
}

a continue not contained in an enclosed iteration statement is equivalent to goto contin.

6.6.3 The return statement [stmt.return]

A function returns to its caller by the return statement.

A return statement with neither an expression nor a braced-init-list can be used only in functions that do not return a value, that is, a function with the return type cv void, a constructor ([class.ctor]), or a destructor ([class.dtor]). A return statement with an expression of non-void type can be used only in functions returning a value; the value of the expression is returned to the caller of the function. The value of the expression is implicitly converted to the return type of the function in which it appears. A return statement can involve the construction and copy or move of a temporary object ([class.temporary]). [ Note: A copy or move operation associated with a return statement may be elided or considered as an rvalue for the purpose of overload resolution in selecting a constructor ([class.copy]).  — end note ] A return statement with a braced-init-list initializes the object or reference to be returned from the function by copy-list-initialization ([dcl.init.list]) from the specified initializer list. [ Example:

std::pair<std::string,int> f(const char* p, int x) {
  return {p,x};
}

 — end example ]

Flowing off the end of a function is equivalent to a return with no value; this results in undefined behavior in a value-returning function.

A return statement with an expression of type void can be used only in functions with a return type of cv void; the expression is evaluated just before the function returns to its caller.

6.6.4 The goto statement [stmt.goto]

The goto statement unconditionally transfers control to the statement labeled by the identifier. The identifier shall be a label ([stmt.label]) located in the current function.