In the switch statement, an expression is evaluated. It is then compared with the values of each case in the structure. If there is a match, the associated block of code is executed. It is used in combination with break and default keywords. They are optional but they are very important.
The break keyword breaks out of the switch block when a certain case match. Without it, the next code block in the switch statement is executed.
The default keyword is used to specify some code to run if there is no case match. It is only used once in it.
Its syntax is:-
// code block
// default code block
|expression||Required. Specifies an expression to be evaluated. The expression is evaluated once and its value is matched with each case. If a match occur, then that block will be executed.|