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;
}
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With