Are you sure this for loop is incrementing the correct variable? It appears that another variable is being initialized and checked by the for loop.