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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.