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
orselect
, 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:
“The books may say that nine-month-olds crawl, say their first words, and are afraid of strangers. Your exuberantly concrete and special nine-month-old hasnt read them. She may be walking already, not saying a word and smiling gleefully at every stranger she sees. . . . You can support her best by helping her learn what shes trying to learn, not what the books say a typical child ought to be learning.”
—Amy Laura Dombro (20th century)