Ending C# coroutine

What is the correct way to yield from a C# coroutine effectively ending it?

I have the following code and I simply want to end the invoking on a certain condition. In this example I’m just simply checking for a null parameter but there are other cases too I can think of.

 IEnumerator checkForCutCard(Card card) {
        if (card == null)
            yield; <<-- not sure what to put here

        if (card.isCutCard) {
            Debug.Log ("The cut card has been dealt");
            vcut_card_appears.Play();
            yield return new WaitForSeconds(vcut_card_appears.clip.length);
        }
 }

You should check the docs first:
http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.StopCoroutine.html

What you have is sort of fine, as you are not looping then the coroutine will exit, you can remove the card == null check and just do this

 IEnumerator checkForCutCard(Card card) {
        if (card != null  card.isCutCard) {
            Debug.Log ("The cut card has been dealt");
            vcut_card_appears.Play();
            yield return new WaitForSeconds(vcut_card_appears.clip.length);
        }
 }

Thanks but I know I could rewrite the if statement, I was just wondering if there was some other way to implement a normal “return;” like you can in a void method which would be the same as if the coroutine got to the very end of its block.

I was aware of this, I was just wondering if this could be done with a 'reserved word" type command like return/yield etc.

yield break;

Thank you :slight_smile: