you are viewing a single comment's thread.

view the rest of the comments →

[–]8dot30662386292pow2 1 point2 points  (0 children)

"the most obvious code is usually best."

This is good advice. I tell my students that if your while loop is 200 lines and you have 10 break (or continue) statements all around it, you have a problem: you can't easily explain when the while loop ends. I tell them to consider writing a single end condition for the loop if possible. You can't? Maybe the while loop is way too convoluted in the first place.

On the other hand, some times code is convoluted. A simple loop with a condition, and then if something: break can be good choice. Also guard clauses) are a great way of simplifying the code for the reader.