Hi,
If I understand your question correctly, You need to repeat calculation until some threshold.
There's a lot of way to do this but I believe this post about recursive will inspire you.
If concept of recursion doesn't fit to you, try to search Fibonachi will help you a lot.