• 9
• 9
• 11
• 13
• 9

# Should I use a switch or a if/if-else...

This topic is 3731 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am writing things out and I noticed that when I use a switch there are instances were more then one "case" has the exact same body of code to be executed... switch(blah){ case 1: doA break; case 2: doB break; case 3: doA breakl } Alternative to this would be something like if(blah == 1 || blah == 2){ doA } else if ( blah == 3){ doB } Regards Chad

##### Share on other sites
switch(blah){  case 1:  case 3:    doA    break;  case 2:    doB    break;}

##### Share on other sites
Quote:
 Original post by SiCraneswitch(blah){ case 1: case 3: doA break; case 2: doB break;}

Ahhh...I see...use the break to my advantage