Coroutine a function within a loop?

hey I’m working on a project in which I have a function that plays a punch animation. after 0.4 seconds the the punch changes into a kick (sort of like a combo). to make this happen I used yield waitforseconds(0.4). for some reason the function doesn’t seem to be working. but when I take the yield out the function works fine (exept that it skips the punch animation and goes directly to the kick.) Is it imposible to coroutine a function within a while loop?

here’s my code, to give you an idea of what I am doing.

var attackf = function(theclass : String){
	if(thenewscript.hit == false){
		attack = true;
		if(theclass == punch){
			sanimation.Play("punch");
			yield WaitForSeconds(0.4);
			sanimation.Play("kick");
			attack = false;
				
		}
		
	}
};

while(true){
	if(Input.GetKeyDown("n")){
		attackf("n");
	}
	yield;
}

this strangely has no response when I call it from within my while loop, (and yes it is not possible for me to make this an update function). n is equal to the punch variable.

that wasn’t my whole while loop mind you.

but when i change my function to this…

var attackf = function(theclass : String){
	if(thenewscript.hit == false){
		attack = true;
		if(theclass == punch){
			sanimation.Play("punch");
			sanimation.Play("kick");
			attack = false;
				
		}
		
	}
};

The animation changes, but not the way i need it too.

Any suggestions? all help is greatly appreiciated. Sorry if this question has an obvious problem that I overlooked, like that time I spelt my function On Tigger Enter.

Don’t you need to call the function as StartCoroutine(attackf("n"));?