0
How to use greater than,less than operators in switch function ? How to use greater than,less than operators in switch function
2 RĂ©ponses
+ 1
unfortunately its nearly impossible, but u can use IF statement or unaryđ
[EDIT]
if not, you can use multiple case statement without breaking them for example
x < 3
use this đ
switch(x){
case 0: case 1: case 2:
//code here
break;
}
but its to difficult and a waste of time, because in the example above đ the statement is true for every positive integer, remember -1, -2, -3, ...-n; also include in (x < 3).
so, using switch to test logical operators isnt the right choiceđ
+ 1
You can also force it, like this đ
x < 3
use this code
switch(x < 3){
case true:
//your code here
break;
}
you can see in any way using IF is the most efficient way
hope this helpđ