func main() { for i := 0; i < 3; i++ { fmt.Println("a") defer fmt.Println(i) fmt.Println("b") } fmt.Println("end") }
a b a b a b end 2 1 0
for i in 0..<3 { print("loop \(i) begin") defer { print("defer \(i)") } print("loop \(i) end") }
loop 0 begin loop 0 end defer 0 loop 1 begin loop 1 end defer 1 loop 2 begin loop 2 end defer 2