Skip to content

Instantly share code, notes, and snippets.

@hi-manshu
Created July 12, 2018 16:22
Show Gist options
  • Save hi-manshu/131186409c17843c3646bb49ef7c6e02 to your computer and use it in GitHub Desktop.
Save hi-manshu/131186409c17843c3646bb49ef7c6e02 to your computer and use it in GitHub Desktop.
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