The SumNumbersTo function is calling itself until the N variable is 0, then it returns, RESUMING the statements of the functions that haven't yet been reached because of the interruption of the call to the next SumNubersTo
say for example we labelled the lines A -> H
The if the variable 'N' > 0 then A,D,E are executed, and the function is then interrupted by the call to a new SumNumbersTo and A,D,E are exeuted again and again unless 'N' = 0, When that happens, then A,B,C are executed, and then the function returns, causing the previous functions statements to be resumed, thus causing F,G,H to be executed several times as the function keeps then returning through the recursed functions
If that helps
say for example we labelled the lines A -> H
Code:
A printf ("Pre if loop (N) (sum) %3lu, %3lu\n", N, sum); // debug print
if (N == 0) {
B printf("If loop N = 0, N = %3lu, sum = %3lu\n", N, sum); // debug print
C return 0;
} else {
D printf("N greater than 0, PreRecurse sum value = %3lu\n", sum); // debug print
E sum = N + SumNumbersTo (N-1); // Look recursion here!
F printf ("Recurse N = %3lu, sum = %3lu\n", N, sum); // debug print
}
G printf ("Sum numbers from 1 to %3lu = %3lu\n", N, sum);
H printf ("N = %3lu, sum = %3lu\n", N, sum); // debug print
return sum;
The if the variable 'N' > 0 then A,D,E are executed, and the function is then interrupted by the call to a new SumNumbersTo and A,D,E are exeuted again and again unless 'N' = 0, When that happens, then A,B,C are executed, and then the function returns, causing the previous functions statements to be resumed, thus causing F,G,H to be executed several times as the function keeps then returning through the recursed functions
If that helps