Switch allows us to choose between several option the basic syntax of the switch statement is as follow:
- Meaning we have the switch expression and then list of cases constant cases, 1,2, 3 and more.
- The number of cases can use can be as many as we need but each one should have a unique constant value.
- This is a simple example where we test the condition of some integer variable called “powerlevel”, in case the power level is equal to 1 than switch on only one led, in case the power level is equal to 2 than switch on two leds and so on...
- Now if there is no match with some constant expression.
For better understanding, please watch this video below.
Dear visitor. Click on "Follow" button from right side above and sign in with your Gmail account. Write unlimited comments on every post. 100% Free