If vs Switch control structure
Hi, there in this short blog post I will be talking about when to use "if condition" or when to use a "switch statement"
"If condition" as it sounds can either be true or false, so when you are checking a condition that will result in true or false although you can use it to check other conditions as well
But in most programming languages you will be enforced to use the "if condition" for true or false checking e.g. true == false, 1 == 2
"Switch statement" as it sounds switches between test cases, and should be used to check between different cases of test against one value.
and selecting the one that matches the giving condition.
Conclusion
The if conditional statement can also be used for selecting cases, but for readability and clarity of code Switch control statement will do the work perfectly.