Hi waseem,
There is a problem with the code that you have posted. You will have to do a wait state and then check the pin again. There are other ways, but this is the simplest. The reson for this is because you want to be sure that the code will work only if you pressed the button, and not just by any chnage in voltage that can be cause from other reason. Also, with your code, the code will be exacuted as long as you are pressing the button.
So lets say you want to toggle a LED on and off, with your code it will turn on and off the led as long as you press the button. and at the end the led could be off.
So, at the end of the day, its good to put some delay or any other function that will make a key press more reliable.
Good luck.