Skip to content

Instantly share code, notes, and snippets.

@julianshen
Created October 24, 2012 03:17
Show Gist options
  • Select an option

  • Save julianshen/3943472 to your computer and use it in GitHub Desktop.

Select an option

Save julianshen/3943472 to your computer and use it in GitHub Desktop.
[Go] Demo defer
package main
import "fmt"
func deferdemo(n int) {
fmt.Println(n)
defer fmt.Println("a")
fmt.Println("b")
if n%3 == 0 {
defer func() {
fmt.Println("c")
fmt.Println("nn")
}()
}
if n%4 == 0 {
defer fmt.Println("d")
}
fmt.Println("e")
return
}
func main() {
deferdemo(6)
fmt.Println("--------")
deferdemo(1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment