Defer in if-statements
- Even if we put the defer call inside an if-statement, the deferred function will only execute at the end of the enclosing function.
examples/defer-no-in-if/defer_no_in_if.go
package main import ( "fmt" ) func main() { if true { fmt.Println("Before") defer fmt.Println("Middle") fmt.Println("After") } fmt.Println("Outside") }