Dec-02-2020, 06:06 PM
The print statement only prints one number. What is happening is that when you reach the base case, you have 6 instances of
As each function finishes, it prints the number. Because of how you have it written, they finish in reverse order, so the numbers are printed in reverse order.
It's not a traditional loop, but recursion is certainly a form of looping. (With different abilities and limitations)
rec_count()
running. Five are waiting for their call to rec_count() to complete. As each one completes, it moves on with the rest of the program.As each function finishes, it prints the number. Because of how you have it written, they finish in reverse order, so the numbers are printed in reverse order.
It's not a traditional loop, but recursion is certainly a form of looping. (With different abilities and limitations)