Material lerp fade out on keyup

Hey, I am currently trying to set up a thing where instead of when the key is lifted setting the material back to black instantly, fade it to black instead. I have tried using things like for loops or different things with lerp but they all either run in 1 frame or get stuck on 1 material. This is the code without the lerp where it just switches instantly. I’m also trying to get the light to fade out with the material.`using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using UnityEngine;
using UnityEngine.Rendering;

public class Main : MonoBehaviour

public string key;

public Material BlackMat;
public Material PinkMat;

Renderer rend;
Light myLight;

// Start is called before the first frame update
void Start()
    myLight = GetComponent<Light>();

// Update is called once per frame
void Update()
    if (Input.GetKeyDown(key))
        rend.material = PinkMat;
        myLight.intensity = 2;
    else if (Input.GetKeyUp(key))
        rend.material = BlackMat;
        myLight.intensity = 0;


use while loop If it works please give alike !!

while (Input.GetKeyUp(KeyCode.A)) { float i--; mylight.intensity == i; }