User Tools

Site Tools


guides:programstyle:goto

This is an old revision of the document!


Use of goto/break/continue/return Statements

All of these statements change the flow of control in a c++ program. They change the behavior of control structures and therefore make it more difficult to understand the final flow of control in a program. For these reasons, the use of these statements is heavily restricted.

goto

continue

break

return

Return statements are used to transfer control from a called function to a calling function. In C++ the return statement may or may not return a value, depending on the function prototype.

Local convention states that each function should have exactly one return statement and that this statement should be the last line of code in the function.

Examples of acceptable use:

// note the return for a void function has no argument.
void PrintHello(void) {
    cout << hello << endl;
 
    return;
}
 
int Square(int n) {
    return n*n;
}
guides/programstyle/goto.1596551731.txt.gz · Last modified: 2022/08/02 11:59 (external edit)