Last active
October 18, 2015 08:08
-
-
Save joyhuang9473/d01d7ef44f6817d866e4 to your computer and use it in GitHub Desktop.
If not conditional on an enumerated value, switch statements should always have a default case (in the case of an enumerated value, the compiler will warn you if any values are not handled). If the default case should never execute, simply assert:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
switch (var) { | |
case 0: // 4 space indent | |
... // 8 space indent | |
break; | |
case 1: | |
... | |
break; | |
default: | |
assert(false); // If the default case should never execute, simply assert | |
} | |
// Braces are required for single-statement loops. | |
for (int i = 0; i < kSomeNumber; ++i) { | |
printf("I take it back\n"); | |
} | |
while (condition) { | |
// Repeat test until it returns false. | |
} | |
// Empty loop bodies should use {} or continue, but not a single semicolon. | |
for (int i = 0; i < kSomeNumber; ++i) {} // Good - empty body. | |
while (condition) continue; // Good - continue indicates no logic. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment