Name
goto statement — Transfers execution to a labeled statement
Synopsis
statement := goto identifier ;
The goto
statement transfers
control to another statement in the same function. The identifier must match a statement label
elsewhere in the function. Statement labels have the form identifier : statement.
Control cannot transfer into a try
block. Transferring control into the
middle of a block and across a declaration results in undefined
behavior unless the declaration is for an uninitialized POD
object.
Example
while (getline(cin, line))
for (size_t i = 0; i < line.size( ); ++i)
if (line[i] == '.')goto
exit; // Break out of nested loops.
exit:
...
See Also
break
, continue
, statement, 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.