STATEMENT: switch
switch
The switch statement tests an expression against a number of case options
and executes the statements associated with the first one to match.
If no match is found, the program looks for a set of default statements
to execute, and if these aren't found either, it carries on with the statement
immediately following switch. An optional break statement with each case ensures
that once a set of statements has been executed, the program exits switch.
If break were omitted, the statements associated with the following case
would also be executed:
Code:
switch (i)
{
case "Chicago" :
document.write
("Flights to Chicago: Saturdays.");
break;
case "London" :
document.write
("Flights to London: Fridays.");
break;
case "New York" :
document.write
("Flights to New York: Fridays.");
break;
case "San Francisco" :
document.write
("Flights to San Francisco: Wednesdays.");
break;
default :
document.write
("Sorry, there are no flights to " + i + ".<BR>");
}
document.write("Thank you for enquiring with Northern Airlines.<BR>");
|