Does a break statement break from a switch/select?

Break statements, The Go Programming Language Specification.

A “break” statement terminates execution of the innermost “for”,
“switch” or “select” statement.

BreakStmt = "break" [ Label ] .

If there is a label, it must be that of an enclosing “for”, “switch”
or “select” statement, and that is the one whose execution terminates
(§For statements, §Switch statements, §Select statements).

L:
  for i < n {
      switch i {
      case 5:
          break L
      }
  }

Therefore, the break statement in your example terminates the switch statement, the “innermost” statement.

Leave a Comment