Skip to content

Instantly share code, notes, and snippets.

@TheBuzzSaw
Last active September 14, 2015 18:00
Show Gist options
  • Select an option

  • Save TheBuzzSaw/7cb88c71eb51c5eb4d80 to your computer and use it in GitHub Desktop.

Select an option

Save TheBuzzSaw/7cb88c71eb51c5eb4d80 to your computer and use it in GitHub Desktop.
K++ proposed switch syntax
/// 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