A Tour of GO (2)--Flow of Contro

2016-01-12  本文已影响0人  陈胖子胖胖胖
  1. For
  1. If
  1. Defer

    Defer funcs are pushed into a stack and executed in a last in first out order when the surrounding function returns.
    func main() {
    fmt.Println("counting")

       for i := 0; i < 10; i++ {
         defer fmt.Println(i)
       }
       fmt.Println("done")
    }
    

    output:
    counting
    done
    9
    8
    ...

上一篇 下一篇

猜你喜欢

热点阅读