|
|
|
The
Goto Statement
The goto Statement
The goto statement allows a program execution to jump to
another section of the function in which it is being used.
In order to use the goto statement, insert a name on a
particular section of your function so you can refer to that
name. The name, also called a label, is made of one word and
follows the rules we have learned about C++ names (the name
can be anything), then followed by a colon. The following
program uses a for loop to count from 0 to 12, but when it
encounters 5, it jumps to a designated section of the program:
#include
int main()
{
for(int Count = 0; Count <= 12; ++Count)
{
cout << "Count " << Count << endl;
if( Count == 5 )
goto MamaMia;
}
MamaMia:
cout << "Stopped at 5";
return 0;
}
kolij

|
|