Reputation: 87
Does anyone know how to return to a base function/script (f/s) when inside a f/s that's called by a f/s that was called by the base f/s? Confusing I know...
base f/s - f/s - f/s --> return from here to base f/s
The regular return
call will only get me to the f/s one level above.
I'm currently using a try-catch
construct in the base f/s to find when the program errors out, but I feel like this is a less than ideal way of doing this.
Thanks, and if I can clarify any other way please let me know.
Upvotes: 1
Views: 105
Reputation: 20309
I advise against using a try
catch
block to achieve this behavior, unless an actual error or exception has occurred. Going this route will result in code that isn't clear.
Instead, have the inner function return a value indicating some status. Then evaluate that status in the middle function to determine if the middle function should return as well.
Here is a simple example
function outer()
middle();
end
function middle()
innerResult = inner()
switch innerResult
case 1:
disp('Executing the guts of middle()');
case -1:
return;
end
end
function retVal = inner()
if returnToOuter
return -1;
else
return 1;
end
end
Upvotes: 2