How can I use goto
across different functions? For example:
int main() {
// ....
REACH:
// ....
}
void function() {
goto REACH;
}
Restrictions in Goto Statement in PythonOne cannot use either of these statements to jump between functions and or modules. It cannot be used to jump into an except line, because there is no exception line in the first place.
We cannot use “goto” to jump from main to other function. In fact we cannot use it jump from any function other than main to any other function.
Goto statement helps in transferring the execution of the program from one line to another. That is why it is a jump statement, as it enables us to jump from one part of our program to another. This is done by using the goto statement and a label name as defined above in the syntax.
NOTE − Use of goto statement is highly discouraged in any programming language because it makes difficult to trace the control flow of a program, making the program hard to understand and hard to modify. Any program that uses a goto can be rewritten to avoid them.
You can't in Standard C++. From $6.6.4/1 of the C++ Language Standard
The goto statement unconditionally transfers control to the statement labeled by the identifier. The identifier shall be a label (6.1) located in the current function.
...or in Standard C. From $6.8.6.1/1 of the C Language Standard
The identifier in a goto statement shall name a label located somewhere in the enclosing function. A goto statement shall not jump from outside the scope of an identifier having a variably modified type to inside the scope of that identifier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With