LYCOS RETRIEVER Beta Retriever Home  |  What is Lycos Retriever?   
Switch: Switch Statement
built 655 days ago
Where the switch statement wins out over an "if/elseif/else" block is it's ability to "fall though" to instructions in following cases until a break is encountered. Coding something similiar using "if/elseif/else" statements could get really messy and buggy really fast depending on the switch statement.
Source:
If an untargetted last statement is executed in a case block, this immediately transfers control out of the enclosing switch block (in other words, there is an implicit last at the end of each normal case block). Thus the previous example could ... have been written:
Source:
The switch statement is similar to a series of IF statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. This is exactly what the switch statement is for.
Source:
SEARCH
MORE ABOUT