Answers for "go stacking defer"

Go
0

go stacking defer

Deferred function calls are pushed onto a stack. When a function returns, 
its deferred calls are executed in last-in-first-out order.
func main() {
	fmt.Println("counting")

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

	fmt.Println("done")
}
Posted by: Guest on January-12-2021

Browse Popular Code Answers by Language