If vs Switch control structure

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.

要查看或添加评论,请登录

Abraham J.的更多文章

  • Thinking In Code.

    Thinking In Code.

    What is a code? According to Wikipedia Code is a system of rules to convert information— such as a letter, word, sound,…

社区洞察

其他会员也浏览了