Getting started with Go — Switch Statements

switch condition {case answer:   //do somethingdefault:}
switch time.Now().Day() {case 0:fmt.Println("Monday")case 1:fmt.Println("Tuesday")case 2:fmt.Println("Wednesday")case 3:fmt.Println("Thursday")case 4:fmt.Println("Friday")case 5, 6:fmt.Println("Weekend!!")}
answer := 15switch {case answer%5 == 0:fmt.Println("It is divisible by 5")fallthroughcase answer%3 == 0:fmt.Println("It is divisible by 3")default:fmt.Println("The answer is neither divisible by 5 or 3")}
It is divisible by 5
It is divisible by 3



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Matthew Boyd

Matthew Boyd

Learning, and posting my findings!