Storing a value

I sort of find what the problem was. If I hold the push button the program stays in a loop turning brightnessMemory to 0.

How can I replace this part of code just to read the button once?

Thanks

if (buttonState == 0) {
brightnessMemory=brightness;
brightness=0;
}