+ 3

How can I transfer control across different function? goto doesn't work in that.

Suppose int main() { start: other statements here myfunc(); } myfunc() { block of statements; goto start; } I know goto don't work like this. goto statement works within same scope. But how can I obtain such transfer control?

19th Dec 2020, 7:44 AM
Bibek Pant
Bibek Pant - avatar
2 ответов
+ 2
Thanks Aaron Eberhardt and NotAPythonNinja . I figured what I needed.
19th Dec 2020, 8:56 AM
Bibek Pant
Bibek Pant - avatar
+ 1
You only have two options: return to the function that called your function or call another function. There's no other option for leaving your scope. In this case you could simply call main at the end of myFunc or call myFunc in a loop from main (which is better because recursion can cause stack overflows). And when you use goto, use it carefully and never jump upwards because this leads to spaghetti code really quickly.
19th Dec 2020, 7:58 AM
Aaron Eberhardt
Aaron Eberhardt - avatar