your first time through the loop there is no value set for gearSpeeds[0] since the if statement skips setting gearSpeed[0]. I guess this is a good thing since if it didn't you first time through you would be picking up gearSpeed[-1].
So gearSpeed[0] has no value set. The coding here has a bug since you don't set any value for gearSpeed[0] but expect to use its value the second time through the loop.