Ok so I have a recursive code from my instructor. I understand how the stack functions (first in last out, last in first out, etc). What I don't get is how the instructor was able to print the popping off of the stack without telling the computer to do so. For example, how does this code displaying the popping without the a command to do so?
Here is the code:
public class Recursion{
public static void main(String [] args){
printParam(1);
}
public static void printParam(int i) {
System.out.println("i = " + i);
if(i < 10) {
printParam(i + 1);
}
System.out.println("i = " + i);
}
}
Looking at the code it looks like it should top at ten, end the program, and trash the stack.