Java Switch and Or statement

java

Solution

Yes, try this:

switch(val){

    case 1: case 3:
        //Do Stuff
        break;

    case 2:
        //Do Stuff
        break;

    default:
        //Do Stuff
        break;

}

Always remember to include the default case too.

Problem

Possible Duplicate: Can I use OR statements in Java switches? I have a switch statement. Is there a way to do an or statement within the switch. Ie ``` switch(val){ case 1 //Do Stuff break; case 2 //Do Stuff break; case 3 //Do Stuff break } ``` Instead do something like ``` switch(val){ case 1 or 3 //Do Stuff break; case 2 //Do Stuff break; } ```

Original source

Related problems