let q = 0.1 S = 0 n = 10000 for k in 1:n S = S + q^k end display(S) #or S = sum(q^k for k in 1:n) # sum takes anything iterable, like vector, or in this part a generator (which we didn't cover and won't ask from you) and just does sums every element up end function closed_form(q,n) """ This just give the same result, and exists to show that we don't always have to do complicated or long loops if mathematical or other knowledge provide easier ways to compute something """ output = 0 if q == 1 output = n+1 else output = (1 - q^(n+1))/(1-q) end return output end