I don't see why it has to be inside the while loop - surely only the code that needs to run many times should be in the loop. One-time code should be before or after the loop, as appropriate.
...