Is there any way to use a condition such as || or && in a case: statement?
switch (int) {
case 0 || 1:
println("Not sure, let me check.");
case 0:
println("Nope.");
break;
case 1:
println("Yup.");
break;
}
Of course, I saw
The operator || is undefined for the argument type(s) int, int
but is there some other way to make it happen?
EDIT:
Below is the example I was actually trying to simplify using OR conditions and switch fall-through.
switch (type) {
case 0:
// as rectMode CORNER
minX = x;
minY = y;
midX = x + x2 / 2;
midY = y + y2 / 2;
maxX = x + x2;
maxY = y + y2;
frameWidth = x2;
frameHeight = y2;
break;
case 1:
// as rectMode CORNERS
minX = x;
minY = y;
midX = (x2 - x) / 2;
midY = (y2 - y) / 2;
maxX = x2;
maxY = y2;
frameWidth = x2 - x;
frameHeight = y2 - y;
break;
case 2:
// as rectMode CENTER
minX = x - x2 / 2;
minY = y - y2 / 2;
midX = x;
midY = y;
maxX = x + x2 / 2;
maxY = y + y2 / 2;
frameWidth = x2;
frameHeight = y2;
break;
case 3:
// as rectMode RADIUS
frameWidth = (x2 / 2);
frameHeight = (y2 / 2);
minX = x - ((x2 / 2) / 2);
minY = y - ((y2 / 2) / 2);
midX = x;
midY = y;
maxX = x + ((x2 / 2) / 2);
maxY = y + ((y2 / 2) / 2);
break;
default:
println("switch default");
break;
}
But as soon as I use
case 0:
case 1:
minX = x;
minY = y;
case 0:
// as rectMode CORNER
midX = x + x2 / 2;
midY = y + y2 / 2;
maxX = x + x2;
maxY = y + y2;
frameWidth = x2;
frameHeight = y2;
break;
then I get an error about Duplicate Case.
So maybe it’s just not going to be possible.