How to exit while loop using keypad?
Because you're using delay() within your while loop you have to ensure that you are pressing the key at the precise moment it is read.

You should not use delay().

Instead take a look at the BlinkWithoutDelay example in the IDE. And also consider implementing a Finite State Machine to know both if you're blinking and what state you're blinking currently is in.