Go data structures - Recursive

1. Introduction recursive

package main
import (
	"fmt"
)

func test(n int) {
	if n > 2 {
		n-- 
		test(n)
	}
	fmt.Println("n=", n) // 2 2 3


	//if n > 2 {
	//	n-- 
	//	test(n)
	//} else {
	//	fmt.Println("n=", n) // 2
	//}

}

func main() {

	n := 4
	test(n)
}

Recursion is important to comply with the principle of:

 

Guess you like

Origin www.cnblogs.com/yzg-14/p/12239530.html