Recursivity, i don't get it

Hello, Kirupians!

I don’t realize how to overcome this issue. The value is returned after the trace. The function runs fine, but don’t return in the required moment, thanks to recursivity and my poor AS knowledge.

function sum(i, t) {
	trace("calculating");
	i++;
	if (i<t) {
		sum(i, t);
	} else {
		trace("end. result is "+t);
		return (t);
	}
}
trace(sum(0, 10));

outputs:

calculating
calculating
calculating
calculating
calculating
calculating
calculating
calculating
calculating
calculating
end. result is 10
undefined

thanks in advance!