Having a hard time working the logic out on this one. Need some guidance here as I am either not understanding the syntax correctly or am getting lost in the logic somewhere...
// *** Returns sum of all integers from 1 to v ***
function SumIntegers(v as integer)
result = 0
for c = 1 to v
inc result, c
next c
endfunction result
How is this returning the sum of all integers? From what I can gather, the following is happening:
result = 0 and c = 1 on first iteration
increment result so result = 1, c = 1
next c
next iteration
result = 1, c = 2
inc result, c
blah
rinse and repeat right? How is anything being added together? Am I missing a vital part? So if I say SumIntegers(4) it would be 1 through 4 in iterations but where is the math done to add each one? Is that where the increment line comes into play?