Skip to content

Instantly share code, notes, and snippets.

@dwihujianto
Created July 22, 2021 07:21
Show Gist options
  • Save dwihujianto/75f6a49c9862e49dcad9695b11d077ce to your computer and use it in GitHub Desktop.
Save dwihujianto/75f6a49c9862e49dcad9695b11d077ce to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math/rand"
)
func main() {
var recursiveAnonymous func(i int)
recursiveAnonymous = func(i int) {
num := rand.Intn(10)
fmt.Println("Anonymous functions could be recursive. ", i, num)
if num == 1 {
fmt.Println("Found ", 1)
return
}
if i < 10 {
recursiveAnonymous(i+1)
} else {
fmt.Println("Max. ", i)
}
}
recursiveAnonymous(1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment