+ 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?
2 Antworten
+ 2
Thanks Aaron Eberhardt and NotAPythonNinja . I figured what I needed.
+ 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.