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.

13
  • 14
    @jpmc26, Better? No. Valid alternative style? Of course. Commented Feb 27, 2018 at 16:48
  • 6
    Better as in harder to mess up when the code is edited later, and not suffering from any notable disadvantages. Commented Feb 27, 2018 at 16:50
  • 4
    Keeping them together because of "loop contents might be long" seems to be a weak argument. When your for content is hard to read then you have other problems than saving the two lines of code. Commented Feb 27, 2018 at 18:37
  • 12
    @jpmc26 Disagree. Braces are superfluous clutter in the shortest, one-liner conditionals as per this answer. Without is more elegant and easier on the eye. They're like a ternary conditional operator. I have never forgotten to add the braces while breaking them out into bigger statement blocks; I'm already adding newlines after all. Commented Feb 27, 2018 at 19:35
  • 3
    It's all a style preference, but if one makes the argument that it's safer, I would disagree with that reasoning. I myself prefer without braces and on the next line, but that doesn't mean it's any more or less valid than other styles Commented Feb 27, 2018 at 19:59