Created
April 19, 2021 10:26
-
-
Save tommylees112/f2cda185a717658823180ece4ae482f6 to your computer and use it in GitHub Desktop.
Using Switches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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