Initial commit
This commit is contained in:
47
12-switch/09-when-to-use/main.go
Normal file
47
12-switch/09-when-to-use/main.go
Normal file
@@ -0,0 +1,47 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 2 {
|
||||
fmt.Println("Gimme a month name.")
|
||||
return
|
||||
}
|
||||
|
||||
// m := os.Args[1]
|
||||
|
||||
// if m == "Dec" || m == "Jan" || m == "Feb" {
|
||||
// fmt.Println("Winter")
|
||||
// } else if m == "Mar" || m == "Apr" || m == "May" {
|
||||
// fmt.Println("Spring")
|
||||
// } else if m == "Jun" || m == "Jul" || m == "Aug" {
|
||||
// fmt.Println("Summer")
|
||||
// } else if m == "Sep" || m == "Oct" || m == "Nov" {
|
||||
// fmt.Println("Fall")
|
||||
// } else {
|
||||
// fmt.Println("ERROR: not a month.")
|
||||
// }
|
||||
|
||||
switch m := os.Args[1]; m {
|
||||
case "Dec", "Jan", "Feb":
|
||||
fmt.Println("Winter")
|
||||
case "Mar", "Apr", "May":
|
||||
fmt.Println("Spring")
|
||||
case "Jun", "Jul", "Aug":
|
||||
fmt.Println("Summer")
|
||||
case "Sep", "Oct", "Nov":
|
||||
fmt.Println("Fall")
|
||||
default:
|
||||
fmt.Printf("%q is not a month.\n", m)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user