static int Factorial(int n) { if (n == 0) return 1; else return n * Factorial(--n); } Of course, the code itself fulfills its intended purpose, and I need to understand its logic of operation. It seems that I understand the work of recursion (and complex recursion) and the work of "return", but something in this example is not so simple. Specifically, what interests me, why without the first "return", which ends the work of "if" and the number that it returns, would this calculation be impossible? I also “stitched” this code in “VS” and it is not clear how this factorial was calculated in general? Because if we write down the values that were calculated, then these were the following expressions:
5 * 4 = 20 4 * 3 = 12 3 * 2 = 6 2 * 1 = 2 1 * 0 = 0 <- these expressions were shown to me by "VS" when the code was being walked (of course, "VS" did not show them to me in the form in which I wrote them here), that is, the first factor is our "n" second factor is - Factorial (- n) and, accordingly, the product is the product of these factors. And I ask how having such works and multipliers managed to correctly calculate factorial? Yes, I understand that such questions arose in me because of insufficient knowledge of the logic of this whole economy (recursion, the keyword "return", etc.) D, and therefore, in fact, I ask this question. I hope, clearly stated the essence of the problem)