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:
“Sinclair Lewis is the perfect example of the false sense of time of the newspaper world.... [ellipsis in source] He was always dominated by an artificial time when he wrote Main Street.... He did not create actual human beings at any time. That is what makes it newspaper. Sinclair Lewis is the typical newspaperman and everything he says is newspaper. The difference between a thinker and a newspaperman is that a thinker enters right into things, a newspaperman is superficial.”
—Gertrude Stein (18741946)