Select Case
devileyes
29 Jul 2011, 13:56I have a variable that can take any value between 0 and 100. I want to create a Select Case statement where each case responds to a range of numbers, as in:
select case <#variable#> {
case <between 0 and 9>
case <between 10 and 19>
case <between 20 and 29>
...and so on
I guess I could do it with 'case <0; 1; 2; 3; 4; 5; 6; 7; 8; 9>' but that does seem cumbersome. Is there another way, or is this on the wishlist for version 5
select case <#variable#> {
case <between 0 and 9>
case <between 10 and 19>
case <between 20 and 29>
...and so on
I guess I could do it with 'case <0; 1; 2; 3; 4; 5; 6; 7; 8; 9>' but that does seem cumbersome. Is there another way, or is this on the wishlist for version 5

Alex
29 Jul 2011, 15:59That's the only way to do it with Q4, unless you resort to some clever trickery - divide the number by 10, use the $instr$ function to find the decimal point if there is one, return the integer portion of the number.
In Q5 you could do this more easily, as it has the concept of integers. You'd probably want to use "else if"s though as this would probably be simpler - again, not something that's available to you in Q4, so you'd have nest a load of "if"s instead.
In Q5 you could do this more easily, as it has the concept of integers. You'd probably want to use "else if"s though as this would probably be simpler - again, not something that's available to you in Q4, so you'd have nest a load of "if"s instead.