this post was submitted on 10 Feb 2024
593 points (96.8% liked)

196

16227 readers
2927 users here now

Be sure to follow the rule before you head out.

Rule: You must post before you leave.

^other^ ^rules^

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 10 points 7 months ago (1 children)
[โ€“] [email protected] 2 points 7 months ago* (last edited 7 months ago)

GNU style is logical, because braces are syntactically a single statement:

while (x == y)
  func1();  // can be replaced by { ... }

However, I prefer to entirely avoid unbraced single statements after while/if:

while (x == y) {
  func1();  // easy to add func2(); later
}

Although this is ok when it fits:

while (x == y) func1();  // brevity!