+ 5

What is the difference between switch case and if...else??? Except for syntax..

27th May 2017, 11:45 AM
Anshul Pawaskar
Anshul Pawaskar - avatar
4 Réponses
+ 9
IF always working when it is with else part... ex:  if(n1>n2) { Printf("TRUE! n1 Is Greater"); } else { Printf("False! n2 Is Greater"); } Switch statement:  It is the MultiConditional control statement where it checks the value of switch choice if it is matched then that case will be Executed directly. Otherwise it goes to default condition case. Ex: switch(grade) { case 1: printf("Distinction"); break; case 2: printf("First Class"); break; case 3: printf("Second Class"); break; case 4:printf("Fail"); break; default: printf("Result Declared"); break; }
27th May 2017, 11:59 AM
BALAGURUNATHAN M
BALAGURUNATHAN M - avatar
+ 7
K bro
27th May 2017, 2:33 PM
BALAGURUNATHAN M
BALAGURUNATHAN M - avatar
+ 2
the if statement goes through all the if..else conditions till it gets the right answer whereas the switch case checks the case choice in the bracket directly and if it doesn't match ut goes to default case.
28th May 2017, 11:00 AM
kshitija kulkarni
kshitija kulkarni - avatar