Just don't do it like that...
Use ifs there. Whiles are just loops that stop the rest of the program until they're done. Which isn't what you want. Just have a key down and a key up so that while it's down a value is true, and when it's released it becomes false. You can use booleans, you know. (Booleans: "true" or "false")