Function 05 Go language --- anonymous function

main Package Penalty for 

Import ( 
	"fmt" 
	"Time" 
) 

// delay the implementation of an anonymous function 
FUNC main071 () { 
	fmt.Println ( "open network") 
	fmt.Println ( "open database") 
	fmt.Println ( "open file" ) 

	// package has value, does not multiplex the value of 
	the defer FUNC () { 
		fmt.Println ( "closed network") 
		fmt.Println ( "Close database") 
		fmt.Println ( "close file") 
	} () 

} 

// concurrency the implementation of an anonymous function 
FUNC main () { 
	/ * anonymous task complicated by a * / 
	Go FUNC (the n-int) { 
		for i: = 0; i <the n-; i ++ { 
			fmt.Println ( "I love Pan Xiaoting") 
			Time. SLEEP (time.Millisecond * 500) 
		} 
	} (. 5) // can pass parameters, return value is passed, it does not make sense, no one anonymous call function returns the value 
	for i: = 0; i < 10;i ++  { 10;{++ i 
		fmt.Println ( "I love LAF")
		time.Sleep(500*time.Millisecond)
	}
}

  

Guess you like

Origin www.cnblogs.com/yunweiqiang/p/11790251.html