You can't use any kind of for loop here. replace it with a while loop and you'll be golden.