Recursive Anonymous Function in Golang Last Updated : 10 Jul, 2020 Comments Improve Suggest changes Like Article Like Report Recursion is a process in which a function calls itself implicitly or explicitly and the corresponding function is called recursive function. Go language supports special feature called anonymous function. It is a function that doesn’t contain any name. It is used to create an inline function. Recursive functions can be declared & defined as anonymous also. A recursive anonymous function is also known as recursive function literal. Syntax: func(parameter-list)(return-type){ // code.. // call same function // within the function // for recursion // Use return statement only // if return-type are given. return }() Example: GO // Golang program to show // how to create an recursive // Anonymous function package main import "fmt" func main() { // Anonymous function var recursiveAnonymous func() recursiveAnonymous = func() { // Printing message to show the // function call and iteration. fmt.Println("Anonymous functions could be recursive.") // Calling same function // recursively recursiveAnonymous() } // Main calling of // the function recursiveAnonymous() } Output: Anonymous functions could be recursive. Anonymous functions could be recursive. Anonymous functions could be recursive. Anonymous functions could be recursive. . . . . Infinite times function calls. Example 2: GO // Golang program to show // how to create an recursive // Anonymous function package main import ( "fmt" ) func main() { // Anonymous function var recursiveAnonymous func(int) // Passing arguments // to Anonymous function recursiveAnonymous = func(variable int) { // Checking condition // to return if variable == -1 { fmt.Println("Welcome to Geeks for Geeks!") return } else { fmt.Println(variable) // Calling same // function recursively recursiveAnonymous(variable - 1) } } // Main calling // of the function recursiveAnonymous(10) } Output: 10 9 8 7 6 5 4 3 2 1 0 Welcome to Geeks for Geeks! Comment More infoAdvertise with us Next Article Recursive Anonymous Function in Golang S shivamraj74 Follow Improve Article Tags : Go Language Go-Functions Similar Reads Anonymous function in Go Language An anonymous function is a function that doesnât have a name. It is useful when you want to create an inline function. In Go, an anonymous function can also form a closure. An anonymous function is also known as a function literal.ExampleGopackage main import "fmt" func main() { // Anonymous functio 2 min read Function as a Field in Golang Structure In Go, you can define functions as fields within a structure (struct). This feature allows you to associate behaviors (methods) directly with data types, enabling a more organized and encapsulated way of managing data and its related operations.Examplepackage mainimport "fmt"// Define a struct with 2 min read reflect.Set() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Set() Function in Golang is used to assigns x to the value v. To access this function, one needs to imports the r 2 min read reflect.ChanOf() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.ChanOf() Function in Golang is used to get the channel type with the given direction and element type, i.e., t re 1 min read reflect.Uint() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Uint() Function in Golang is used to get v's underlying value, as a uint64. To access this function, one needs to 2 min read Like