Skip to content

Instantly share code, notes, and snippets.

@tommylees112
Created April 19, 2021 10:26
Show Gist options
  • Save tommylees112/f2cda185a717658823180ece4ae482f6 to your computer and use it in GitHub Desktop.
Save tommylees112/f2cda185a717658823180ece4ae482f6 to your computer and use it in GitHub Desktop.
Using Switches
package main
import (
"fmt"
"time"
)
func main() {
today := time.Now().Weekday()
fmt.Printf("Today is: %v\n", today)
fmt.Println("When's Saturday?")
// switch finds first match and executes it
switch {
case today+0 == time.Saturday:
fmt.Println("Today.")
case today+1 == time.Saturday:
fmt.Println("Tomorrow.")
case today+2 == time.Saturday:
fmt.Println("In two days.")
default:
fmt.Println("Too far away.")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment