Use an index i rather than re-using a state variable.