done=False
while not done:
for level in range(1,13):
Code...
while running:
Code.....
#10 - Win/Lose check
if healthvalue<=0:
done=True
running=0
exitcode=0
print "aaa"
我在python上有这个游戏,当健康状况低于0时,它应该退出循环。但是,即使我在if语句中声明done=True
,但循环仍然没有退出,尽管运行确实变为0.我还通过打印“aaa”来检查,它确实打印了,但是还是没有完成等于True以退出循环。
请帮忙! 是否与for循环有关?
答案 0 :(得分:1)
如果你有循环层,你需要突破每一个。
做=假
while not done:
for level in range(1,13):
Code...
# add "not done" as a condition to get out of this loop:
while running and not done:
Code.....
#10 - Win/Lose check
if healthvalue<=0:
done=True
# break out of the for loop
if done == True:
break