Advertisement
Koepnick

switch case

Jan 15th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.38 KB | None | 0 0
  1. switch os := runtime.GOOS; os {
  2.     case "darwin":
  3.         fmt.Println("OS X.")
  4.     case "linux":
  5.         fmt.Println("Linux.")
  6.     default:
  7.         // freebsd, openbsd,
  8.         // plan9, windows...
  9.         fmt.Printf("%s.", os)
  10.     }
  11. }
  12.  
  13. t := time.Now()
  14. switch {
  15.     case t.Hour() < 12:
  16.         fmt.Println("Good morning!")
  17.     case t.Hour() < 17:
  18.         fmt.Println("Good afternoon.")
  19.     default:
  20.         fmt.Println("Good evening.")
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement