0PricingLogin
Go Academy · Lesson

switch Statements in Go

Tagged and tagless switch, fallthrough

switch Basics

Go's switch is more powerful than in C: no fall-through by default, and cases can have multiple values:

day := "Monday"
switch day {
case "Saturday", "Sunday":
    fmt.Println("Weekend")
default:
    fmt.Println("Weekday")
}

No Implicit Fallthrough

In Go, each case body breaks automatically — unlike C where you must write break explicitly:

  • Cleaner code, fewer bugs
  • Use fallthrough explicitly when you need C-like behavior (rare)

All lessons in this course

  1. if Statements and Init Expressions
  2. The for Loop: All Patterns
  3. switch Statements in Go
  4. break, continue and Labels
← Back to Go Academy