0

For example, I want to have it like

switch (var){
    case <10:
        System.out.println("var is lower than 10!");
}

If there is already a similar question that is answered, can I please have the link, thanks!

  • 1
    you don't, you would use an if-else if structure. either that, or the waterfall principle, but if it 's about large values, I would strongly recommend against – Stultuske Oct 12 '21 at 06:11
  • `switch` statement is not the right tool for this kind of comparison; use `if-else` statement – Yousaf Oct 12 '21 at 06:13
  • This question was closed but a link to a question about JavaSCRIPT was added? It's completely unrelated. – Sebastiaan van den Broek Oct 12 '21 at 06:16
  • The Java Language Specification for [Java 11](https://docs.oracle.com/javase/specs/jls/se11/html/jls-14.html#jls-14.11) and for [Java 17](https://docs.oracle.com/javase/specs/jls/se17/html/jls-14.html#jls-14.11) in the end both state that a SwitchLabel must be either a constant expression or the name of an enum constant. `<10` is not a neither and therefore not allowed by Java. – Thomas Kläger Oct 12 '21 at 20:07

0 Answers0