Skip to content

Latest commit

 

History

History
40 lines (28 loc) · 923 Bytes

recursion.md

File metadata and controls

40 lines (28 loc) · 923 Bytes
layout
default

Recursion

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)
}

Output

120

Try It Out | Source Code

Contributors

<< Home Page | Previous << Closure | Next >> Boolean Expressions