What are the conventions to be followed for the usage of switch case

Posted by Andre Scott | Updated on

Below are the list of conventions should be taken care,

  1. The expression can be of type either number or string.
  2. Duplicate values are not allowed for the expression.
  3. The default statement is optional. If the expression passed to switch does not match with any case value then the statement within default case will be executed.
  4. The break statement is used inside the switch to terminate a statement sequence.
  5. The break statement is optional. But if it is omitted, the execution will continue on into the next case.

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers