Recursion of C# Code - Trouble understanding
For one of the coding projects in C# methods, it wanted me to create a function that would take the level of the game, and add the points for each level before to the points of the last level. Example: level 3 = 3 points. add 3 + 2 + 1. I was expecting a Forloop since the code seemed to be iterated through each level but instead the following worked: static int Points(int levels) { //your code goes here if (levels == 1) { return 1; } return levels + Points(levels - 1); } I'm having trouble understanding how this snippet of code is able to go through each of the previous levels. From just reading it, it seems like it would on return level + Points(level - 1) just one time. Can anyone explain this to me? I'm not sure if i missed something. Thanks!