Home »
Code Examples »
Golang Code Examples
Golang - Demonstrate the concept of indirect recursion Code Example
The code for Demonstrate the concept of indirect recursion
package main
import (
"fmt"
)
func print_one(n int) {
if n >= 0 {
fmt.Println("In first function:", n)
print_two(n - 1)
}
}
func print_two(n int) {
if n >= 0 {
fmt.Println("In second function:", n)
print_one(n - 1)
}
}
func main() {
print_one(10)
print_one(-1)
}
/*
Output:
In first function: 10
In second function: 9
In first function: 8
In second function: 7
In first function: 6
In second function: 5
In first function: 4
In second function: 3
In first function: 2
In second function: 1
In first function: 0
*/
Code by IncludeHelp,
on March 1, 2023 07:02