printnum recursion details

The Function

printnum

a) the first printnum with a parameter of 1, printnum(1), gets pushed onto the stack.
b) prints 1
c) evaluates the if statement that 1 < 9 d) calls recursion method printnum(1+1) printnum1

a) printnum(2) gets pushed onto the stack
b) method prints 2
c) evaluates the if statement that 2 < 9 d) calls recursion method printnum(2+1) printnum2

we continue in this manner until printnum(1) to printnum(8) gets pushed onto the stack…and their corresponding couts get printed in the console.

a) printnum(9) gets pushed onto the stack.
b) print start 9
c) the if statement evaluates to false.
d) Then the next statement is to print ‘end: 9’

printnum3

a) After the printing of ‘end: 9’, our execution arrow hits the end of the function. Thus, printnum(9) gets popped off the stack.
b) We then resume execution at the recursive call that happened at printnum(8)
c) execution arrow moves down and prints ‘end: 8’
d) execution arrow hits end of function at printnum(8). printnum(8) gets popped off the stack

printnum4

a) printnum(8) gets popped off stack
b) resume execution at recursion call inside of printnum(7)
c) execution arrow moves down and prints ‘end: 7’.
d) execution arrow hits end of function at printnum(7). printnum(7) gets popped off stack

printnum6

So we keep going until…

a) we come to the recursive call in printnum(2) function.
b) execution arrow moves down and prints ‘end:2’
c) execution arrow hits end of function printnum(2). Thus, printnum(2) gets popped off the stack.
d) resumes execution at recursive call inside of printnum(1)
e) execution arrow move down and prints ‘end: 1’.