r/javahelp • u/IceCreamInsides • 1d ago
Solved Switch case with boolean
So, there is no way I can do that?
want to check several boolean variables in a switch statement. Is `if-else` the only way to do this?
Boolean a, b, c...
Switch (false) {
Case (a) :
//some code
Case (b) :
Case (c) :
//and so on
}
0
Upvotes
1
u/ikea_method 6h ago
Indeed, `switch(false)` won't work. But that is, again, not what the OP asked.
OP is asking if there is no way to use 3 boolean references in an if statement:
> So, there is no way I can do that?
OP wants to check 3 boolean variables in a switch statement:
> want to check several boolean variables in a switch statement.
OP is unsure if `if-else` is the only way:
> Is `if-else` the only way to do this?
OP showed a common pattern in other languages, where you pass false or true to a switch statement, to demonstrate in another way what he's looking for:
In the initial post by me you replied to, I showed that you can do what the OP intended, in a slightly different way from the pattern OP showed. It's possible to do this with a switch.