Jul-17-2018, 02:20 AM
With my suggestion you can completely skip out any time you want to, and restart where you left off. I'm not saying use recursion, I'm saying fake the recursion.
def silly(n, x): m = n stack = [iter(range(m))] total = 0 while stack: try: i = stack[-1].__next__() except StopIteration: stack.pop() continue total += i if total >= x: break if i == 5: m -= 1 stack.append(iter(range(m))) return totalBy keeping the stack of iterators yourself, you have complete control over it. You could pass the stack around between different functions doing different things.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures