How can I turn off a led when releasing a button?

How can I turn off a led when releasing a button? I mean, I want a program that works like this: When I press the first button the led turns on, I should release the first button and then I have to press a second button and while releasing it, the led should turn off, how can I do that?

The state change detection example (in the IDE examples) shows how to detect when the button becomes pressed and becomes released (as opposed to when the button is pressed or released).

void loop(){
if (digitalRead(button1) == LOW){
digitalWrite (ledPin,  HIGH);
}
if (digitalRead(button2) == LOW){
digitalWrite (ledPin, LOW);
}

}

In setup():
pinMode (buttonX, INPUT_PULLUP);

Wire the button so the pin connects to Gnd when pressed.