Switch Statement



Utilizing a switch conditional statement instead of an if statement can sometimes present clearer code logic. When we have a variable or an expression containing variables that may have different resulting values followed by different actions, it is a good opportunity to use switch.

switch (<expression>) {
       case <result 1>:
              <action 1>;
       case <result 2>:
              <action 2>;
       case <result n>:
              <action n>;
              <other action>;

Copyright information

© Ron Dai 2019

Authors and Affiliations

  • Ron Dai
    • 1
  1. 1.SeattleUSA

Personalised recommendations