Quote:
> The documentation seeems to indicate that the label in a switch statement
is
> always an equality with the expression. IOW the label value must _equal_
the
> expression.
> Is this true or is it possible to use other comparison operators (e.g.,
> greater than) inside the switch statement?
Shamelessly borrowed from Michael Harris's
VBScript solution to the same
problem:
for (i=0; i<10; i++) {
x = Math.floor(Math.random()*150)+1;
switch (true) {
case (x<50): WScript.echo(x+" is less than 50."); break;
case (x<100): WScript.echo(x+" is between 50 and 100."); break;
default: WScript.echo(x+" is more than 100.");
}
}
Warning: Tested in JScript 5.6. This might not work in other versions of
J/Java/ECMAScript!
--
Be humble, if thou would'st attain to wisdom. Be humbler still, when wisdom
thou hast mastered. -Helena Petrovna Hahn Blavatsky
=-=-=
Steve
-=-=-