Confirmed users, Bureaucrats and Sysops emeriti
419
edits
Line 48: | Line 48: | ||
== Control Flow == | == Control Flow == | ||
* Minimize indentation using return, break, and continue where appropriate. | * Minimize indentation using return, break, and continue where appropriate. Prefer return (break, continue) statements to cast out abnormal cases, instead of nesting "if/else" statements and indenting the common cases. | ||
void | void | ||
MyFunction(int n) | MyFunction(int n) | ||
Line 66: | Line 64: | ||
} | } | ||
* If an "if" statement contains a return statement, do not use "else". | |||
if (condition) { // bad | if (condition) { // bad | ||
DoThis(); | DoThis(); | ||
Line 79: | Line 77: | ||
DoThat(); | DoThat(); | ||
* Avoid similar arbitrary patterns and non-sequiturs: | |||
if (condition) { // bad | if (condition) { // bad | ||
DoThis(); | DoThis(); |