-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunc_defer.go
30 lines (26 loc) · 1.04 KB
/
func_defer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// It's schedules a function call to be run after the function completes.
// Deferred functions are run even if a run-time panic occurs.
// Used to delay execution of a statement until function exits.
// Useful to group "open" and "close" function together.
// Run in LIFO(Last in, First out) order
// Arguments evaluated at time defer is executed, not at time of called function execution.
package main
import (
"fmt"
)
func main(){
fmt.Println("Start")
fmt.Println("Process")
fmt.Println("End")
fmt.Println("_____________________________________________")
fmt.Println("Difference b/w normal func & defer func ")
fmt.Println("First")
defer fmt.Println("Second") // defer function used, it will be execute after func exits.
fmt.Println("Third")
fmt.Println("_____________________________________________")
fmt.Println("Difference b/w normal func & defer func ")
defer fmt.Println("First Entry")
defer fmt.Println("Second Entry")
defer fmt.Println("Third Entry")
fmt.Println("_____________________________________________")
}