Last active
September 14, 2015 18:00
-
-
Save TheBuzzSaw/7cb88c71eb51c5eb4d80 to your computer and use it in GitHub Desktop.
K++ proposed switch syntax
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 statements will use a structure closer to that of if-statements: | |
| /// they are one line unless you use braces. | |
| /// No more break statements. The _default_ behavior is breaking out of a block. | |
| /// Fallthrough is achieved through either comma-separates lists or 'jump' keyword. | |
| switch (value) | |
| { | |
| // One line style. | |
| case (7) DoSomething(); | |
| // One new line indent style. | |
| case (8) | |
| DoSomethingElse(); | |
| // Traditional brace block. | |
| case (9) | |
| { | |
| DoYetAnotherThing(); | |
| ContemplateLife(); | |
| } | |
| // Multiple values (traditional fallthrough cases). | |
| case (10, 14, 19) | |
| { | |
| ProcessDataTables(); | |
| jump 9; // Goto the case block for the value 9. | |
| } | |
| // Value ranges (shorthand fallthrough cases). | |
| case (20 to 29) Believe(); | |
| default | |
| { | |
| FixThings(); | |
| Avast(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment