1

I trying to insert "break" code in switch statement in java for stop looping output. I insert the break in switch statement, but the java is giving the "break is unusual statement" and break is greyed out.

switch (Stardose) {
    case "Student", "student" -> System.out.println(Stardose = "Student");
    case "Office", "office" -> System.out.println(Stardose = "Office");
    case "Pro", "pro" -> System.out.println(Stardose = "Pro");
    case "Xstream", "xstream" -> System.out.println(Stardose = "Xstream");
    default -> throw new IllegalArgumentException("Invalid edition " + Stardose);
}
MWiesner
  • 8,868
  • 11
  • 36
  • 70
Harish M
  • 11
  • 1
  • 3
    Can you show a [mcve]? Your code doesn't even have a `break` in it, or a loop. – Sweeper Aug 27 '22 at 05:34
  • 1
    When you use the new `switch` syntax, there is no fall-through behavior, hence, you don’t need a `break` statement, unless it’s a conditional break. But as Sweeper said, you should provide an actual example. – Holger May 23 '23 at 15:11

0 Answers0