Statement

Expressionless switch

Without a tag expression, switch behaves as a switch on true. Cases are evaluated in order until a match. Ordinary cases do not fall through. Example output: 'mid'.

Formal Syntax & Structure

go syntaxgo
switch { case condition: ... }

Working Example

Example Snippetgo
package main
import "fmt"
func main() {  n := 7  switch {  case n > 10:    fmt.Println("high")  case n > 5:    fmt.Println("mid")  default:    fmt.Println("low")  }}
Go Reference