Switch is a statement that tests a variable for equality in a list of given conditions. It is somehow a summarized version of IF when you have a lot of conditions.
This flow chart may help you understand better, and this webpage too:
The default syntax of switch goes like this:
switch (expression) case “condition” : outcome [default:statement] //This is used when the variable input isn’t a valid option.
So, for the purpose of this mastery, lets create a program were the user can input his points on masteries so far and tell him if his good or screwed. Do as follows:
Your program should look something like this:
Now let’s test it:
Let’s just play with another value:
Great! Now you know what and how to use switch conditional.
]]>Switch is a statement that tests a variable for equality in a list of given conditions. It is somehow a summarized version of IF when you have a lot of conditions.
This flow chart may help you understand better, and this webpage too:
The default syntax of switch goes like this:
switch (expression) case “condition” : outcome [default:statement] //This is used when the variable input isn’t a valid option.
So, for the purpose of this mastery, lets create a program were the user can input his points on masteries so far and tell him if his good or screwed. Do as follows:
Your program should look something like this:
Now let’s test it:
Let’s just play with another value:
Great! Now you know what and how to use switch conditional.
]]>