Iteration Using for-Statements

1 SumZ

The for-statement is a convenient way of expressing iteration. This fits well when you know how to express the range of values over which the iteration variable should iterate. The class SumZ contains a very simple for-loop summing the five elements of the vector z.



2 Simulation of SumZ




3 Simulation of SumZ and HideVariable

Since the scope of the iteration variable is the body of the for-statement, it may hide other variables with the same name, like the constant k in HideVariable.



4 Simulation of HideVariable