Switch Statement - Typical Syntax

Typical Syntax

In most languages, a switch statement is defined across many individual lines using one or two keywords. A typical syntax is:

  • The first line contains the basic keyword, usually switch, case or select, followed by an expression which is often referred to as the control expression or control variable of the switch statement.
  • Subsequent lines define the actual cases (the values) with corresponding sequences of statements that should be executed when a match occurs.

Each alternative begins with the particular value, or list of values (see below), that the control variable may match and which will cause the control to go to the corresponding sequence of statements. The value (or list/range of values) is usually separated from the corresponding statement sequence by a colon or an implication arrow. In many languages, every case must also be preceded by a keyword such as case or when. An optional default case is typically also allowed, specified by a default or else keyword; this is executed when none of the other cases matches the control expression.

Read more about this topic:  Switch Statement

Famous quotes containing the word typical:

    It is not however, adulthood itself, but parenthood that forms the glass shroud of memory. For there is an interesting quirk in the memory of women. At 30, women see their adolescence quite clearly. At 30 a woman’s adolescence remains a facet fitting into her current self.... At 40, however, memories of adolescence are blurred. Women of this age look much more to their earlier childhood for memories of themselves and of their mothers. This links up to her typical parenting phase.
    Terri Apter (20th century)