Well, there’s always the break command. You can flag that after a key has been pushed, you want to break. And then outside the switch, you break. However, why do you need to have a while(true) loop anyway?
solved How to get out of this cycle?