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",它确实打印,但是to并不等于True,以便退出循环。
请帮助!是否与for循环有关?
发布于 2015-10-29 17:16:06
如果你有层层的循环,你需要打破每一个循环。
done=False
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:
breakhttps://stackoverflow.com/questions/33420563
复制相似问题