Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The switch statement also performs conditional logic. It takes up a bit more space as far as the number of lines it occupies, but switch statements are less verbose in their syntax and are easier to read when creating long lists of conditions.
The switch statement is a function call that is passed an expression, which is then used to check against different values in case comparisons. If a case clause resolves to true, code within the case statement is executed. The break statement at the end of each case breaks out of the switch statement if a case resolves to true. If a case clause resolves to false, the statement moves on to the next case statement in the switch block. If no case statements return true, a default clause can handle any resulting action, much like an else statement.