Let's take a simple switch-case that looks like:
@Override public void onClick(View v) { switch (v.getId()) { case R.id.someValue : case R.id.someOtherValue: // do stuff break; } }
I wonder why it is not allowed to use the ||
operator? Like
switch (v.getId()) { case R.id.someValue || R.id.someOtherValue: // do stuff break; }
The switch-case
construct is pretty similar to an if-else
statement, you can use the OR operator in an if
however. What are the backgrounds for a switch-case
to not accept this operator?
The switch-case construct is pretty similar to an if-else statement, you can use the OR operator in an if however.
The simple answer is No. You cant use it like that.
If you are eager to know how to use an OR condition in a Ruby switch case: So, in a case statement, a , is the equivalent of || in an if statement.
No. It's not possible because a case must be a constant expression.
dude do like this
case R.id.someValue : case R.id.someOtherValue : //do stuff
This is same as using OR operator between two values Because of this case operator isn't there in switch case
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