Reputation: 401
So I was building a script and needed a conditional. I went with a variabled-while loop for control like so.
while a == True
While coding it I forgot the variable and ended up with this:
while True: ## Num hands control loop
try:
v_NumHands = int(raw_input("Enter number of hands desired, 1 - 7:"))
if (v_NumHands < 1) or (v_NumHands > 7): ## Checks num of hands is in range
print("Not correct, try again.")
else: break
except ValueError:
print("Enter a number.")
print("Hands: %s") %(v_NumHands)
I figured that it would not work as the 'break' should break out of the 'if' conditional, but not the 'while loop.' However it does work and I don't know why.
So why does this work?
Upvotes: 0
Views: 86