It should depend on your use of the program. If you are making a program that has a lot of inappropriate conditions then you should go for the if condition. But if your condition depends on some kind of number or some string, you should replace if-else statements with switch case condition, where you have to decide if some 'case' happens, in which block of code is to be executed.
For better understanding switch to the example:
switch(status) {
case 'active':
//background green
break;
case 'onhold':
//background yellow
break;
case 'inactive':
//background red
break;
default:
//background grey
break;
}
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
It should depend on your use of the program. If you are making a program that has a lot of inappropriate conditions then you should go for the if condition. But if your condition depends on some kind of number or some string, you should replace if-else statements with switch case condition, where you have to decide if some 'case' happens, in which block of code is to be executed.
For better understanding switch to the example:
switch(status) {case 'active':
//background green
break;
case 'onhold':
//background yellow
break;
case 'inactive':
//background red
break;
default:
//background grey
break;
}