Why this matters
Omitting braces in control structures (if, for, while) can cause logical errors when modifying the code later. Always using braces improves code clarity and prevents unintended execution flows.
Ensure that all control structures (if, for, while) use braces `{}` even for single statements.
Omitting braces in control structures (if, for, while) can cause logical errors when modifying the code later. Always using braces improves code clarity and prevents unintended execution flows.
Side-by-side examples engineers can pattern-match during review.
if (condition) doSomething();if (condition) {
doSomething();
}if (condition) doSomething();if (condition) {
doSomething();
}From the same buckets as this rule.