Can someone please explain this to me?
The difference between Switch and if-else statement is below:
This is the general syntax of if-else ladder:
if (condition1) { //Body of if }
else if (condition2) { //Body of if }
else if (condition3) { //Body of if }
else { //default if all conditions return false }
And this is the general syntax for switch:
switch ( variable )
{
case : //Do Something
break;
case ://Do Something
break;
default: //Do Something
break;
}
The if-else ladder is of type strict condition check, while switch is of type jump value catching.
Advantages of switch over if-else ladder: