control flow - How to break out of multiple loops in Python? -
control flow - How to break out of multiple loops in Python? -
given next code (that doesn't work):
while true: #snip: print out current state while true: ok = get_input("is ok? (y/n)") if ok == "y" or ok == "y": break 2 #this doesn't work :( if ok == "n" or ok == "n": break #do more processing menus , stuff
is there way create work? or have 1 check break out of input loop, another, more limited, check in outside loop break out if user satisfied?
edit-fyi: get_input short function wrote supports showing prompt , default values , fanciness , returns stdin.readline().strip()
my first instinct refactor nested loop function , utilize return
break out.
python control-flow
Comments
Post a Comment