August 2000
Intermediate to advanced
800 pages
13h 15m
English
An alternative to if-elseif-else structures is the switch statement, which works on the assumption that you compare a single expression to a set of possible values. Figure 3-3 demonstrates the structure of a switch statement.
The root expression inside a switch statement is evaluated and then compared to each expression following a case statement. At the end of the list of cases you can put a default statement that works exactly like an else statement; it matches if no other case matches.
Notice that cases don't have curly braces after them. This reveals an important difference between ...
Read now
Unlock full access