Python Forum
Don't Understand Recursive Function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Don't Understand Recursive Function
#2
This is the basic structure of your function:
Output:
rec_count(5) print 5 rec_count(4) print 5
If we expand all calls like that, we get:
Output:
rec_count(5) print 5 rec_count(4) print 4 rec_count(3) print 3 rec_count(2) print 2 rec_count(1) print 1 rec_count(0) print 0 return 0 print 0 -- not called because the return ends this call print 1 print 2 print 3 print 4 print 5
Hope that helps.
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 stranac - Dec-02-2020, 06:03 PM

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