function geoSum(q,N) for k in 1:N S = S + q^k end return S end println(geoSum(0.1,100)) println(geoSum(1.1,100)) #The idea is that a function is easily reusable and can thus be part of a larger program, whereas a global definition of the loop in a script stops there and having to copy paste that if you need it elsewhere is both tedious and ends up with more lines of code which makes is more difficult to read.