Created
March 24, 2017 08:38
-
-
Save md2perpe/d3639194fdd8f5b774d8b9ddf17fb667 to your computer and use it in GitHub Desktop.
Switch instead of if
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
// Instead of | |
if (n == 42) | |
single_stmt; | |
// one can write | |
switch (n) | |
case 42: | |
single_stmt; | |
// Having no case makes the `single_stmt` not be run: | |
switch (n) | |
single_stmt; // Not run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment