9.5. The switch Statement

The switch statement is a control statement that handles multiple selections by passing control to one of the case statements within its body. The switch statement takes this form:

switch (expression)
{
  case constant-expression:
    statement
    jump-statement
  default:
    statement
    jump-statement]
}

where

  • expression is an integral or string type expression.

  • statement is the embedded statement(s) to be executed if control is transferred to the case or the default.

  • jump-statement transfers control out of the case body.

  • constant-expression is the value that causes control to be transferred to a specific case.

Control is transferred to the case statement whose constant-expression matches expression. The switch statement can include ...

Get .NET for Java Developers: Migrating to C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.