The idea is that the highest exponent is also the number of times that you need to call the function that calculates terms. So if you write a function that can compute any one term, you end up with code similar to what I suggested.

CalculateTerm(a,x,5) for example would return ax^5 to you, you add it to F_x, then you do the 4th power term, etc.