Created
September 8, 2015 04:19
-
-
Save gspencerfabian/402913f3a09ad00a0150 to your computer and use it in GitHub Desktop.
golang - example switch statement
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" | |
| "os" | |
| "strconv" | |
| ) | |
| var arg1 = os.Args[1] | |
| var arg2 = os.Args[2] | |
| var arg3 = os.Args[3] | |
| func main() { | |
| num1, _ := strconv.ParseFloat(arg2, 64) | |
| num2, _ := strconv.ParseFloat(arg3, 64) | |
| switch { | |
| case arg1 == "add": | |
| fmt.Println(num1 + num2) | |
| case arg1 == "subtract": | |
| fmt.Println(num1 - num2) | |
| case arg1 == "multiply": | |
| fmt.Println(num1 * num2) | |
| case arg1 == "divide": | |
| fmt.Println(num1 / num2) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment