Avatar
omochimetaru 8/29/2018 7:35 AM
func main() { for i := 0; i < 3; i++ { fmt.Println("a") defer fmt.Println(i) fmt.Println("b") } fmt.Println("end") }
7:36 AM
a b a b a b end 2 1 0
7:36 AM
deferはfuncにどんどん貯め込むのか
7:36 AM
for i in 0..<3 { print("loop \(i) begin") defer { print("defer \(i)") } print("loop \(i) end") }
7:36 AM
loop 0 begin loop 0 end defer 0 loop 1 begin loop 1 end defer 1 loop 2 begin loop 2 end defer 2
7:36 AM
Swiftのdeferと全然違うんですね