Go code
day := "Monday"
switch day {
case "Monday":
fmt.Println("Start")
case "Friday":
fmt.Println("Finish")
default:
fmt.Println("Middle")
}Line-by-line explanation
- Day stores Monday.
- Switch examines day.
- The Monday case matches.
- Start is displayed.
- Go stops after that case automatically.
Expected output
StartThis is the expected result.
Unlike some languages, ordinary Go cases do not need break to prevent automatic fall-through.