When we play Recursive Function, we need precautions , because it's recursive in nature. There's a big problem if base condition not valid then it repeat infinite times. Which cause panic in go-lang. Today, I use simple example such as factorial
package mainIf you're a detective then you may notice that in func fact return again fact. This line
import (
"fmt"
)
func main() {
i := fact(5)
fmt.Println(i)
}
func fact(n int)int {
if n == 1{
return n
}
return n * fact(n-1) } Play
actually recursive line which repeat over and over, until base condition are true
Comments
Post a Comment