You will need to reset the counter (i) to 0 each time at the start.