Making LEDs do a slow fade to off when a button is let go

Hello all, I am currently trying to have a few neopixel LED’s hooked up to my arduino. So far Everything has been working, currently im trying to do a mod where if i press a button, the Led will turn on, but when i let go off the button it will slowly fade off. The current code I have somewhat does this, heres a small snippet of the code (The way I have it set up is that when the button is pressed the signal becomes ‘0’)
sorry if the code is sloppy I’m still just trying things before I organize the entire code

if (a == 0) { // When button is pressed

for (int i=0; i<3; i++)

strip.setPixelColor(i, 255, 255, 255);

strip.show();

}

else // When button is let go

{

for (int i=0; i<3; i++)

strip.setPixelColor(i, 0, 0, 0);

strip.show();

}
}

The problem with the code is the ‘else’ statement is always running which can be a problem because previously i put a for loop to fade out the leds but since the else statement is always running it just immediately ran the fade out on repeat since the button is technically not pressed. Is there a way to rework the code so that the else statment can only be activated when variable ‘a’ goes from 0 → 1 rather then when a is 1.

I hope you guys understand, thanks for any help

That is what the [state change detection method](http://only be activated when variable 'a' goes from 0 -> 1 rather then when a is 1.) does, it can sense the transitions as opposed to the states.