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