It looks like you forgot to increment index1. You might want to use a for loop instead to make it more obvious.