Confirmed users
446
edits
Ehoogeveen (talk | contribs) (Reflect change from |T *t| to |T* t|. Also remove the edge cases that are obvious with the new style.) |
(Language about bracing multi-line stuff inexplicably doesn't track long-standing practice -- fix it to) |
||
| Line 67: | Line 67: | ||
if(condition) /* bad */ | if(condition) /* bad */ | ||
if (condition) /* OK */ | if (condition) /* OK */ | ||
* In a conditional, if the consequent (and, if present, | * In a conditional, if the condition and consequent (and, if present, any number of <code>else if</code>/<code>else</code> alternatives and associated conditions) occupy single lines, no braces are used. | ||
if (today == "Tuesday") | if (today == "Tuesday") | ||
puts("I don't have my wallet on me."); | puts("I don't have my wallet on me."); | ||
else | else | ||
puts("I would gladly pay you on Tuesday for a hamburger today."); | puts("I would gladly pay you on Tuesday for a hamburger today."); | ||
However, if '' | However, if ''any'' condition occupies multiple lines, or if a consequent or alternative occupies multiple lines (regardless whether it's a single statement or multiple statements), every consequent and alternative is braced. | ||
if (canSwingFromWeb) { | if (canSwingFromWeb) { | ||
p->swingFromWeb(); | p->swingFromWeb(); | ||
} else { | } else { | ||
MOZ_ASSERT(p->isSpiderPig()); | |||
p->doWhateverSpiderPigDoes(); | p->doWhateverSpiderPigDoes(); | ||
} | |||
if (apingOtherMonkey) { | |||
MOZ_ASSERT(monkey->wantsAttention(), | |||
"why else would he be aping another monkey?"); | |||
} | |||
if (hungryForBananas && // and a comment makes the line long enough for a linebreak | |||
wantsAttentionInTheWorstWay) | |||
{ | |||
p->eatBananasAndPreen(); | |||
} | } | ||
* Conditions with multi-line tests should put the brace on the new line to provide a visual separation between the condition and the body. | * Conditions with multi-line tests should put the brace on the new line to provide a visual separation between the condition and the body. | ||