Categories
Coding and Logic

Playing with Switches

While coding, you need to control over something, so we have “Control Structures” in our language. Most of the programing language have control structures. And you are building an application, so you (not you exactly, your code) need to make a decision, then your code start comparing things and take the correct decision and moves ahead. It uses conditional statements for comparing stuffs and take action as per the logic. When we say conditional statements, normally some people understand if, else stuff. And they just ignore the switch statement. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. But I have seen some people using long series of else if/elseif instead using switch. Here I am going to discuss few tricks with the Switches (switch statement).