WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Go - function closure


Functions closures are nameless features and can be used in dynamic programming.


package deal predominant

import "fmt"

func getSequence() func() int 
   i:=zero
   go back func() int 
      i+=10
	  return i  
   


func principal()
   /* nextNumber is now a characteristic with i as 0 */
   nextNumber := getSequence()  

   /* invoke nextNumber to increase i by way of 10 and go back the equal */
   fmt.Println(nextNumber())
   fmt.Println(nextNumber())
   fmt.Println(nextNumber())
   
   /* create a brand new series and notice the end result, i is zero once more*/
   nextNumber1 := getSequence()  
   fmt.Println(nextNumber1())
   fmt.Println(nextNumber1())

When the above code is compiled and accomplished, it produces the subsequent end result
$go run predominant.Pass
10
20
30
10
20