Can Switch Case statements be outside the void loop?

How would I write the code to make the hash key come out of the while loop?

Pseudo code :

while (key is not '#')
{
  read key from the keypad
  do whatever you need with other input
}