A simplified example illustrating the concept of using functions to control the inner loop:
stack = range(1, 500)
def stack_loop():
ticker = 0
while stack:
x = stack.pop()
# Your implementation here
if ticker >= 121:
print("Ticker ticked")
return True
else:
print("Ticker increased")
ticker += 1
return False
while True:
if stack_loop():
break
Move the inner loop's logic to an external function and use the return
statement to control if you have to break out of the main loop or not.
Hope it helps :)
EDIT: You could also move the entire block to the function and simply return
from it:
stack = range(1, 500)
def main_loop():
while True:
ticker = 0
while stack:
x = stack.pop()
# Your implementation here
if ticker >= 121:
print("Ticker ticked")
return
else:
print("Ticker increased")
ticker += 1
main_loop()