Home Segments Index Top Previous Next

386: Mainline

In the example in Segment 385, the value of the parameter, index, becomes 1, 2, 3, and 4, with the statement in the block evaluated each time:

Iteration Value of index New value assigned to sum
1 1 0 $+$ 570 $=$ 570
2 2 570 $+$ 720 $=$ 1290
3 3 1290 $+$ 640 $=$ 1930
4 4 1290 $+$ 640 $=$ 2650

You may be more comfortable with the index-based approach, because the principal feature of Array instances is that you can get at them using a parameter as an index. On the other hand, using a parameter as an index, rather than as an element, produces a bulkier program, and hence a more error-prone program.