Getting a 4-digit number from a keypad

Hello,
Your code...

while(key = keyPad.getKey() == NO_KEY)
{
    // Do nothing
}
// Use key

Doesn't compiles... gives an error that now I don't remeber. But when I change to:

while(keypad.getKey() == NO_KEY)
{
    // Do nothing
}
if(keypad.getKey()!= NO_KEY);
{                
 char key = keypad.getKey();
 int myInt = key;
 Serial.println("You have pressed ");
 Serial.print(key);
 Serial.println("The corresponding number is ");
 Serial.print(myInt);
 myNum[i]= myInt;
 i = i+1;
}

You can check that even I have left the "// Do nothing" of your code... But now compiles...
And is giving back "0000"
I don't see where I'm calling key so many times as you say. First I read as a character the keypad is giving me, and the change to a number int temporary, and with this temporary int, create the differente digits of the number... But only reading the key once.
Explain better my fail or better your code...

Cheers