How to wait for Coroutine to finish?

I would like to call a coroutine function and return a value. To do so, I am calling function StartCheck() which calls a StartCoroutine(WaitStartCheck()). Below is a sample code to explain better what I’m trying to do:

private bool checkComplete = false;
private bool check = false;

bool StartCheck() {

   checkComplete = false;
   check = false;

   StartCoroutine(WaitStartCheck());

   while (!checkComplete) {
       //some code
       print(Time.deltaTime);
   }

   return check;
}

IEnumerator WaitSStartCheck() {

   yield return new WaitForSeconds(5.0f);
   
   if (condition)
       check = true;
   else
       check = false;

   checkComplete = true;
}

The problem is that the while loop is freezing Unity. How can I make this to work?

Thank you!

Why would you use boolean when you can get the program to wait for the coroutine without stopping:

bool check;

IEnumerator Somewhere()
{
    yield return StartCoroutine(WaitSStartCheck());
    if(check){}
}
IEnumerator WaitSStartCheck() {
 
    yield return new WaitForSeconds(5.0f);
    
    check = condition;
 }

Check out Run.Coroutine of CoroutineHelpers. It returns a Run object which has an isDone property.