Can Switch Case statements be outside the void loop?

Hi guys,

Thank you for your help so far. I am still a little stuck, it doesn't look like my "while loop" is working. I got an error saying "expected unqualified-id before 'while' ". I am not sure where I am going wrong. Does anyone have any advice?

const byte ROWS = 4; //four rows
const byte COLS = 4; //four colums
//define the smybols on the buttons of the keyboard

char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte rowPins[COLS] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[ROWS] = {6,7,8,9}; //connect to the colum pinouts of the keypad

//initalize an instance of class NewKeypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );



while (keys != '#') {
   static int number = 0;
  char key = keypad.waitForKey();
   switch(key)
   {
       case '0'...'9':
          number *= 10;
          number += key - '0';
          break;

       case 'A':
          useForCaseA(number);
          number = 0;
          break;

       case 'B':
          useForCaseB(number);
          number = 0;     
          break;

       case 'C':
          useForCaseC(number);
          number = 0;
          break;

       case 'D':
          useForCaseD(number);
          number = 0;
          break;
          
       case '*': // Set Home Position
          break;

       case '#': // Move Motors on Position and Start Test
          break;   
   }
}

Many thanks,
Suf