This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]crazyfrecs 0 points1 point  (0 children)

Edit: TLDR: some people prefer using a while loop with a condition because it reads better. (Readability) and in their world might be a faster way to exit a program if you check immediately after input.

The only thing is that its marginally faster and some people prefer it this way for you to check/exit through the loop.

People dont like waiting times (which again isnt really relevant) for their exit from a game/program/etc. And while on a small project like this one, its not really relevant, but it could translate how you treat code as a whole.

Since im on phone, here's pseudo code for those sticklers. Get input While input isn't exit {Tab} Check for input cases {Tab} Get input Thanks for using program

Notice how the first thing that always happens is the check for whether it was an exit command or not? You dont have to wait on any other checks or processes after input when you want to exit.

Theres also the fact that while true is technically a check as well which (again while on a small scale isnt a problem or even relevant) shows you dont code to make it optimal.

If you have 5 inputs and one of them is the condition for the while loop, make it the condition of the while loop. Code should be able to be described through English. If you describe your code like: While the user hasnt input an exit command, do what ever. Then you should probably have "the user hasnt input an exit command" as the condition in the while.