Do nested co-routines skip some Update() frames?

I’m currently writing a game that has a co-routine for a game loop within a “GameManager” script as follows…

public sealed class GameManager : MonoBehaviour
{
    private void Start()
    {
        StartCoroutine(GameLoop());
    }

    private IEnumerator GameLoop()
    {
        while (true)
        {
            yield return StartCoroutine(NestedTest());

            yield return null;
        }
    }

    private IEnumerator NestedTest()
    {
        if (Input.GetMouseButtonDown(0)) Debug.Log("Click detected!");

        yield return null;
    }
}

The code is supposed to detect every click that the user makes. In other words, if they click 40 times, it should print the debug message 40 times, but it doesn’t; it misses a lot of the clicks! I can’t see why this is not working, as the GameLoop() should be waiting until the NestedTest() routine finishes, and then yield until the next frame; in other words, the Input.GetMouseButtonDown(0) should theoretically run on every frame, and thus detect every click that occurs!

Funnily, the following code works and detects every click…

public sealed class GameManager : MonoBehaviour
{
    private void Start()
    {
        StartCoroutine(GameLoop());
    }

    private IEnumerator GameLoop()
    {
        while (true)
        {
            if (Input.GetMouseButtonDown(0)) Debug.Log("Click detected!");

            yield return null;
        }
    }
}

The reason why I want to write the game loop with nested co-routines is to break it down into logical steps (note that these nested co-routines call further nested co-routines that wait for input .etc. which is why I can’t just have them as normal methods).

Can anybody enlighten me as to why the first snippet doesn’t work, but the second one does?

In the first example, you purposely wrote code to check for a click on every other frame. yield return ... means to wait at least one frame. Your main coroutine waits for the first to finish, then waits one extra frame before calling it again.