Python Forum
Don't Understand Recursive Function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Don't Understand Recursive Function
#3
The print statement only prints one number. What is happening is that when you reach the base case, you have 6 instances of 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)
Reply


Messages In This Thread
Don't Understand Recursive Function - by muzikman - Dec-02-2020, 05:30 PM
RE: Don't Understand Recursive Function - by bowlofred - Dec-02-2020, 06:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  with open context inside of a recursive function billykid999 1 651 May-23-2023, 02:37 AM
Last Post: deanhystad
  Why recursive function consumes more of processing time than loops? M83Linux 9 4,431 May-20-2021, 01:52 PM
Last Post: DeaD_EyE
  Combine Two Recursive Functions To Create One Recursive Selection Sort Function Jeremy7 12 7,684 Jan-17-2021, 03:02 AM
Last Post: Jeremy7
  Execution of Another Recursive Function muzikman 5 3,129 Dec-04-2020, 08:13 PM
Last Post: snippsat
  list call problem in generator function using iteration and recursive calls postta 1 2,023 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  Recursive function returns None, when True is expected akar 0 3,474 Sep-07-2020, 07:58 PM
Last Post: akar
  factorial using recursive function spalisetty06 12 4,254 Aug-25-2020, 03:16 PM
Last Post: spalisetty06
  Recursive Function sridhar 7 2,955 Jul-14-2020, 07:53 PM
Last Post: deanhystad
  Nested Recursive Function not Returning Etotheitau 2 2,383 May-09-2020, 06:09 PM
Last Post: Etotheitau
  Information "creeps up" in recursive function InigoMontoya 2 1,942 Sep-17-2019, 06:25 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020