Use while loop instead of do~while loop.