How can my program exit a function call? I have a recursive function that, when a condition is satisfied, calls itself.
def function( arg ):
if (condition):
...
return function( arg + 1 )
My guess at how it works: if the condition is not satisfied, the function call will terminate. In my program, that doesn’t seem to be the case — the condition is violated but the program jumps to the return statement (perhaps the only return statement it sees?).
Is there some sort of exit() that I could put in an else clause?
As listed, your code will always just return
None. It goes through all the recursion, and does this until the condition is not met, and then drops out the end of the function and returnsNone.For example, try this:
and build up from this to do something useful.