Created
July 12, 2018 16:22
-
-
Save hi-manshu/131186409c17843c3646bb49ef7c6e02 to your computer and use it in GitHub Desktop.
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 | |
| //imported the fmt package | |
| import "fmt" | |
| //main function gets called when the program executes | |
| func main() { | |
| //we initialize the variable with value 2 and without any data-type | |
| var i = 2 | |
| switch i { | |
| //here the case is executed based on the value of i | |
| case 1: | |
| //prints if value of i is 1 | |
| fmt.Println("One") | |
| case 2: | |
| //prints if value of i is 2 | |
| fmt.Println("Two") | |
| case 3: | |
| //prints if value of i is 3 | |
| fmt.Println("Three") | |
| } | |
| } | |
| >>go run switchexample.go | |
| >>Two |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment