Skip to content

Instantly share code, notes, and snippets.

@afreeland
Created April 5, 2018 12:49
Show Gist options
  • Save afreeland/cb6601fce67865e47500003ee782b1bc to your computer and use it in GitHub Desktop.
Save afreeland/cb6601fce67865e47500003ee782b1bc to your computer and use it in GitHub Desktop.
Go: basic branching
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello, playground")
//foo := 1
if foo := 2; foo == 1 {
fmt.Println("bar")
} else {
fmt.Println("buz")
}
// Initialize bar, and then check cases
switch bar := 1; bar {
case 1:
fmt.Println("bar is 1")
case 2:
fmt.Println("bar is 2")
}
// Advanced Case
test := 1
switch {
case test == 1:
fmt.Println("test is equal to 1")
case test > 2:
fmt.Println("test is greater than")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment