Created
July 22, 2021 07:21
-
-
Save dwihujianto/75f6a49c9862e49dcad9695b11d077ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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