Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use OR statements in Java switches?

Tags:

java

I'm wondering if I can use or in switch-case in Java?

Example

switch (value)
{
   case 0:
      do();
      break;

   case 2 OR 3 
      do2();
      break;
} 
like image 851
Amira Elsayed Ismail Avatar asked Mar 05 '12 12:03

Amira Elsayed Ismail


1 Answers

There is no "or" operator in the case expressions in the Java language. You can however let one case "fall through" to another by omitting the break statement:

switch (value)
{
   case 0:
      do();
      break;

   case 2:  // fall through
   case 3:
      do2();
      break;
} 
like image 162
aioobe Avatar answered Oct 14 '22 16:10

aioobe