In my opinion, that is an odd-looking for statement. Typically, the end condition would be a constant value. I think the more conventional approach would be to use a while loop to check for a value != ''.
I realize that this does not explain the behavior that you are seeing, but perhaps this would be a cleaner solution.