What exactly is the yield command?

Alright so I understand that a yield are basically like bookmarks of code. However, I thought they were bookmarks until the next time the function is called. It seems that a yield is simply a “return here on the next frame” – Don’t get me wrong, it works perfectly. But I guess I don’t really understand them. Here’s my simple test that leads me to believe that yield is pretty much a frame break.

void Start ()
{
    StartCoroutine(Go());
}
IEnumerator Go()
{
                print("hit1" + "-" + Time.frameCount);
    yield return null;  //return next frame
                print("hit2" + "-" + Time.frameCount);
    yield return null;  //return next frame
                print("hit3" + "-" + Time.frameCount);
    yield return null;  //return next frame
                print("hit4" + "-" + Time.frameCount);
    yield return null;  //return next frame
                print("end" + "-" + Time.frameCount);
    yield break;
}

So just to make sure, is yield pretty much just a “check back in on the next frame”?

This is the output:

hit1-1
hit2-2
hit3-3
hit4-4
end-5

You can think of yield as a thread operation. In each frame the Unity engine waits for all of its ‘threads’ to finish before advancing to the next frame (where ‘threads’ might be coroutines, OnGUI() methods, etc.). So you are correct: yield finishes (or pauses) execution of the code at that point and tells the Unity engine ‘I am done for this frame.’ When the next frame starts, it picks up where it left off, with all variable and state information that it had the previous frame.

Hope that helps.