Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

1
  • Despite this question having some good answers already, I wanted to specifically upvote this because it makes an important point: to me, having anything other than a simple bound checking in the for-loop (for(...; i <= n; ...)) actually makes the code harder to read because I have to stop and think about what is happening here and might miss the condition altogether on the first pass because I don't expect it to be there. For me, a for loop implies that you are looping over some range, if there is a special exit condition it should be made explicit with an if, or you can use a while. Commented Feb 28, 2018 at 9:09