0
How to use greater than,less than operators in switch function ? How to use greater than,less than operators in switch function
2 Antworten
+ 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😀