Keyword

Go case keyword

Introduces a branch in a switch or select. Expression switches compare candidate values; type switches inspect dynamic types; select cases perform a send or receive. These forms are not interchangeable. Example prints cold.

Formal Syntax & Structure

go syntaxgo
case expressionList: | case typeList: | case communication:

Working Example

Example Snippetgo
package main
import "fmt"
func main() {  switch 3 {  case 1, 2:    fmt.Println("warm")  case 3:    fmt.Println("cold")  }}
Go Reference