Difference between object oriented object based programming language

What is difference between if statement and switch statement ?

Answer : Please see below :

if statement

switch statement

if can be used to test multiple conditionsswitch cannot be used to test multiple conditions
multiway execution is not availableswitch provides multiway execution
if statement is not good choice if number of condition is more. Because switch uses index mapping on variable choice to the corresponding solutionsswitch statement is preferable if number of test conditions are more
for multiple condition if statement is not developer friendly and including maintenance of code could be toughswitch is generally more dense for multiple condition
in if statement you can evaluate complex expressionsswitch evaluate expression using constant
if statement accepts all data typesswitch statement accepts only primitive types as key and constants for cases
Performance of if statement will be slow for multiple conditionPerformance is faster because switch uses index mapping

 

Leave a Reply

Your email address will not be published. Required fields are marked *