Skip to content
Advertisement

How to keep running a nested While in python

I have a pygame. in it there are a few nested while loops, running all of them one time accomplish one round, how do I keep rounds going and going, never stop?

Repeat{I have a pygame. in it there are a few nested while loops, running all of them one time accomplish one round, how do I keep rounds going and going, never stop? I have a pygame. in it there are a few nested while loops, running all of them one time accomplish one round, how do I keep rounds going and going, never stop? I have a pygame. in it there are a few nested while loops, running all of them one time accomplish one round, how do I keep rounds going and going, never stop? I have a pygame. in it there are a few nested while loops, running all of them one time accomplish one round, how do I keep rounds going and going, never stop? }Repeat

JavaScript

Advertisement

Answer

You have too much nesting there. Because all the inner while loops never terminate, the program also never gets back to the pygame.event.get() call, which is why you’ll also find that the program doesn’t respond to input (including closing the window). There is also a lot of duplicated code.

It’s better to keep the robot’s current direction in a variable, let’s call it direction, and change the value of that when it reaches the edge. To make the code easier to understand, you can define some constants at the top:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement