1

So I have this code:

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

when i click a certain area i want it to break the loop

2
  • 1
    it can't be "and" mutually exclusive things. Commented May 6, 2020 at 2:39
  • 1
    You need to add more information. When does gameEnd become True for instance. What is the context? Commented May 6, 2020 at 2:51

1 Answer 1

2

You can create a variable outside of your while loop and set it to true, then when your condition restart() is met, set the variable to false. This will prevent the while loop body from executing.

Something like this would work:

var loop = True
while loop:
    if restart():
        loop = False
        break
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.