layout |
---|
default |
Example demonstrates how to use recursion in the Go programming language. Recursion is a function calling itself. Recursion is a key aspect in functional programming.
package main
import "fmt"
func main() {
fmt.Println(calculateFactorial(5))
}
func calculateFactorial(val int) int {
if val == 0 {
return 1
}
return val * calculateFactorial(val-1)
}
120
<< Home Page | Previous << Closure | Next >> Boolean Expressions