Repair broken while

If the loop is not executed the old code will not correctly skip the loop.