使用 python 中的函数打破循环

breaking loops with a function in python

所以我有这个代码:

def restart(x, y):
        if gameEnd == True:
            if x >= -78.0 and x <= 78.0 and y >= -52.0 and y <= 52.0:
                return True
screen.listen()
screen.onscreenclick(restart)

while True:
if restart():
            break

当我点击某个区域时,我想让它打破循环

您可以在 while 循环之外创建一个变量并将其设置为 true,然后当满足条件 restart() 时,将该变量设置为 false。这将阻止 while 循环体的执行。

像这样的东西会起作用:

var loop = True
while loop:
    if restart():
        loop = False
        break