+ 1
why cant we use <> in switch statements like switch (age){ case < 16}, why we cant use <?
4 Respuestas
+ 1
Because case/switch is specifically used for determined values such as 1 4 7 or 8 (for example), and using the < or > is selecting a wide range of numbers, and for that you have if(x > y) { }
+ 1
Language syntax... Ruby supports such range in case... when... else
+ 1
Actually, you can. Consider this code:
Switch (True)
case (age<16):
This is within the language limits, even though it's not considered to be very readable programing...
0
ty guys