It appears that you're incrementing i several times in the same iteration, hence it's exiting quicker. If all of them are occurring under the same condition, then combine them under the same if...