in JavaScript and also I've seen it in PHP : You can use a logical expression inside you cases : For Example :
switch(true){
case (d<10):
document.write("Less than 10");
break;
case (d==10):
document.write("Equal to 10");
break;
case (d>10):
document.write("Greater than 10");
break;
default:
document.write("Some dumb error. Probably not a number.");
}
I was wondering if we can do this in Java ... say I needed a to compare a very large range.
case 1 :
case 2 :
...
case 5000:
case 5001:
default:
It would be tedious to do. I could wrap my cases inside if statements but i was wondering it could be done like in JavaScript or PHP.