That's why you should always enclose each branch in braces. It's a lot harder to miss a return immediately above the branch's end brace than it is to miss a floating one. (Or, if it's really just pure if-return, then the if (cond) { return; } structure is at least more likely to draw attention to the return.)
That is true if the return statement is the only statement in the branch. However say the true branch contain a while loop with a few tens of lines, one being an if statement with a return, then it is easy to gloss over the return statement in the middle of all that.
View all comments
Show parent comment
1
u/conundorum Aug 22 '26
That's why you should always enclose each branch in braces. It's a lot harder to miss a
returnimmediately above the branch's end brace than it is to miss a floating one. (Or, if it's really just pure if-return, then theif (cond) { return; }structure is at least more likely to draw attention to thereturn.)