I created my own recursion example and commented it out. It might help someone.
Click here http://pastebin.com/m2xgmHMT to see it in pasteBin with colour coding
COPY AND PASTE IT TO A NEW PROJECT AND YOU WILL SEE FOR YOURSELF WHAT IS HAPENING
[code]// this function gets called from main and with value 2 being passes to this paramether named countVar
// now we can use it inside this function and do whatever we want with it.
void methodToCall (int countVar)
{
// The “true” part of the if statement only runs once when the program comes to an end
// this is where it should end
// but not until all frames removed from the stack
// the top frame would be with the countVar value of 0;
// it gets removed, but now it must continue where it stopped
// printf(“Now lets continue where we left before and the value of countVar is %d\n”,countVar);
//
if (countVar == 0){ // “true part of the if statement"
printf(”\nThat is it, it is the end of the program countVar value is %d\n", countVar);
printf(“Lets clear the stack and remove frame by frame starting with the top frame\n”);
} else {
printf(“The value of countVar is %d lets deduct 1 from countVar and call this method again \n”, countVar);
int oneLessVar = countVar -1;
methodToCall(oneLessVar);
// this is where it stopped so now it needs to finish this function before we can remove the frame from the stack.
printf("\nNow lets continue where we left before and the value of countVar is %d\n",countVar);
}
// this runs when if loop has finished its job
printf("Frame with countVar with the value of %d is removed\n", countVar);
}
int main(int argc, const char * argv[])
{
// this is where it all starts
methodToCall(2);
return 0;
}[/code]