Go defer 03
2019-03-05 本文已影响0人
JaedenKil
package main
import "fmt"
func main() {
var i = 2
for ; i <= 5; i++ {
defer fmt.Println(i)
}
fmt.Println("Outside the loop 01")
for ; i <= 10; i++ {
defer fmt.Println(i)
}
fmt.Println("Outside the loop 02")
}
Outputs:
Outside the loop 01
Outside the loop 02
10
9
8
7
6
5
4
3
2