Go defer 03

作者: JaedenKil | 来源:发表于2019-03-05 15:20 被阅读0次
    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
    

    相关文章

      网友评论

        本文标题:Go defer 03

        本文链接:https://www.haomeiwen.com/subject/feqouqtx.html