wait until something while checking for something else

private IEnumerator WaitForShield(float waitTime)
{
print(“hi1”);
shield.SetActive(true);

        if (Input.GetKey(KeyCode.I))
        {
            if (Input.GetKey(KeyCode.S) && NotShielding == false)
            {
                anim.SetInteger("AnimParameter", 8);
                shield.SetActive(false);
                yield return new WaitForSeconds(0.667f);
                anim.SetInteger("AnimParameter", 7);
                
            }
        }
        yield return new WaitUntil(() => (!Input.GetKey(KeyCode.I)));
        shield.SetActive(true);
        print("hi2");
        anim.SetInteger("AnimParameter", 7);
        print(anim.GetInteger("AnimParameter"));
        yield return new WaitForSeconds(waitTime);
        print("hi3");
        shield.SetActive(false);
        NotShielding = true;
    }

I need the
if (Input.GetKey(KeyCode.I))
to run while the
yield return new WaitUntil(() =>(!Input.GetKey(KeyCode.I)));
happens
Using a while loop where the if is crashes Unity

Delete the yield return new WaitUntil(() => (!Input.GetKey(KeyCode.I)));

And write

while(!Input.GetKey(KeyCode.I)) { yield return null; }