Skip to main content
1 of 2
Pat
  • 1.6k
  • 1
  • 15
  • 12

Your alternatives are not as bad as you may think. Good code should:

  1. Clearly indicate with good variable names / comments under what conditions the loop should be terminated. (The breaking condition should not be hidden)

  2. Clearly indicate what is the order of doing operations. This is where putting the optional 3rd operation ( DoSomethingElseTo(input) ) inside the if is a good idea.

That said, it is easy to let perfectionist, brass-polishing instincts consume a lot of time. I would just tweak the if as mentioned above; comment the code and move on.

Pat
  • 1.6k
  • 1
  • 15
  • 12