Go defer 02

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
Last in first out.

你可能感兴趣的:(Go defer 02)