Skip to content
Wisdom And Wonder

Wisdom And Wonder

Happiness, Creativity, And Computing.

  • About
  • Archive
  • Friends
  • Privacy Policy
  • RSS

(Go Lang) Recursion (GBEN)

Go by Example

Example

  • It has it

package main
import "fmt"
// This fact function calls itself until it reaches the base case of fact(0).
func fact(n int) int {
  if n == 0 {
    return 1
  }
  return n * fact(n-1)
}
func main() {
  fmt.Println(fact(7))
}
5040

Attribution

Share me 🙋!

  • Tweet
  • WhatsApp

You might also like some of these

Author grantPosted on 2017/08/18Categories ArticleTags GBEN, Go Lang, Programming Language

Post navigation

Previous Previous post: (Go Lang) Closures (GBEN)
Next Next post: (Go Lang) Pointers (GBEN)
  • About
  • Archive
  • Friends
  • Privacy Policy
  • RSS
Wisdom And Wonder Privacy Policy Proudly powered by WordPress
My site uses cookies so that I can remember you and understand how you use my site. If you do not agree with my use of cookies, then please block them.I understand.Privacy Policy