How do you detect coroutines end?

I move some objects using coroutine, and I will do something else when the coroutines end.
How can I detect the coroutine ends? This is not easy for me.
My code is like this…

bool coroutineEnd = false;  

void Update() {  
    if (coroutineEnd)  doFuntionB();  

    if (!coroutineEnd) doFunctionA();  
}  

void doFunctionA() {  
    for(int i=0; i<4; i++) {  
        StartCoroutine(moveObj());  
    }  
    coroutineEnd = true;  
}  

IEnumerator moveObj() {  
    while(true) {  
        if (condition)  break;  
        transform.Translate(Vector3.right * Time.deltaTime);  
        yield return 0;  
    }  
}  
  
void doFunctionB() {  
    ....  
    coroutineEnd = false;  
}  

Problem is doFunctionB(0 starts before doFunctionA() ends.
Is this right way to handle this kind of job?
Thanks in advance for any advice.

Your coroutine won’t ever end, because of the while true. If you change true to something that actually can become false, then the coroutine ends at the end of the scope. You could pass a delegate to call then, or call a function etc.

There are several things you can do. The easiest is using a flag. Use a simple bool set to true at the first line of the coroutine and false at the last line of the coroutine. In your update function just ckeck for that bool, and if it is true (coroutine is executing) doFunctionA, else doFunctionB.

If you just want to chain execution of coroutines/functions, check the use of delegates.