Lecture13 def maxVal question. http://dpaste.com/566617/ It seems like the program should stop before getting to line 9 as i reaches 0. I guess the loop from line 5-8 doesn't return out of the function ending the process, but only returns back to the outer recursive loop? Does anyone have a better explanation?
sounds like you got it ... it is not usually referred to as a loop. at line 8 a new instance of the function is created and the current instance is 'frozen' at line 8. the new instance of the function starts at line 1 or 2. this happens everytime line 8 is executed, until eventually one of the instances executes line 6 or 7 where it 'returns'. at this point the 'immediately previous' (better wording?) instance of the function continues execution at line 9 and it returns (to its immediately previous instance) at either line 9 or 11. notice that there is also another possible recursion path at line 10. if you work it out by hand it is easy to see that it mimics (pretty well) the path taken on the descision tree that was ilustrated in the lecture.
I like the term "frozen". Makes it a bit easier to wrap my head around. What I guess I am missing is where the values returned by lines 6 and 7 return to? Going to watch decision tree portion of lecture again and map out as you suggested.
Ah, i think I see... The returns from line 6 and 7 really only matter on the last instance when the value is returned. Thanks for the help bwCA.
Join our real-time social learning platform and learn together with your friends!