First off, indent your code correctly - it makes it a lot easier to see what is goign on:
function fun(unsigned integer n)
begin
result = 1
while n != 0
n = n - 1
result = result + 2 * n
end while
return result
end
Second, you only get recursion when a function directly or indirectly calls itself, as in the classic Factorial example:
function Factorial(int n)
begin
if (n <= 1) return 1
return n * Factorial(n - 1)
end
Your code doesn't do that, so it isn't recursive.
Instead it uses a loop, reducing the value of
n
each time round the loop, and exiting the loop only when
n
has reached zero.
So look at the code and generate each term that is added to
result
each time you go round. Write them down on a piece of paper, and it should be pretty obvious what it is doing, and how it works.
This is a simple bit of code, and you should be able to analyse it for yourself with a bit of effort - and that starts you "thinking the right way" about analysing more complex tasks. If we do that stage for you, it means you don't learn how to do that, and future tasks will become much harder as a result!