Jump to content
  • Advertisement
Sign in to follow this  
Zaris

Pythons - while true:

This topic is 2611 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In python, the standard to be wrap the game loop in a while True statement using a break statement to exit the program doesn't seem right to me. I have always felt loops should have a defined end condition - while some variable is true and changing that variable to false when the game is ready to end. I am planning on writing some tutorials and was wondering should I go with the standard idiom or use the while condition loop?

Share this post


Link to post
Share on other sites
Advertisement
I don't think that either of these is "the standard idiom", as I see both used quite commonly.

The choice is largely a matter of style (although either method may be "cleaner" or more obvious depending on how you want your loop to behave e.g. conditions are checked at the start/end of an iteration whereas break exits the loop immediately).

I generally try to structure loops in the way which best reflects my mental model of the process, so my intention is hopefully obvious to whoever might be reading the code. I also avoid loop conditions which have side effects, rely on the return values of assignments etc e.g. "while (someVariable = someStream.getNextValue()) != NULL"

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!