Summing Values in an Array
coryco2
Posts: 107
What would be the most compact, efficient SPIN code to use for summing the values in a variable array whose values change frequently?
I would like something better than Sum := ArrayItem[0] + ArrayItem[1] +...ArrayItem[n].
Any suggestions?
I would like something better than Sum := ArrayItem[0] + ArrayItem[1] +...ArrayItem[n].
Any suggestions?
Comments
If you need the sum only rarely, do what Duane Degn said. But if you need the sum every time you change any single value, update the sum every time you change a value by subtracting out the old value of the element you're about to overwrite and then adding in the new value, with something like this: