Coroutine is being skipped.

I’m trying to create a Coroutine, which is supposed to check if a bool is true. Although, it seems to just skip that and run the rest of the code.

Here’s the Ienumerator:

IEnumerator waitForInput(bool checkThis)
	{
		while (checkThis == true)
		{
				yield return null;
		}
		yield return null;
	}

Here’s the function that calls the StartCoroutine

void mainMenu()
{
		textScreen.text = "Welcome to the main menu!

Please select your desired program:

  1. WifiHack

  2. CameraHack

  3. Exit";

     	StartCoroutine(inputChanged);
    
             //check what the input was here.
    
     	Debug.Log("Didn't work.");
     }
    

As you can see, I’m telling it to start the coroutine and check if my bool is true. I’ve created a Debug.log message, so I know if it has been skipped. That log message fires each time I play the game.

The inputChanged bool is set to false on Start() function. Same goes with the mainMenu() function being called:

void Start()
{
inputChanged = false;
mainMenu();
}

Someone was having the same problem as me, although that was with a keypress: “Waiting for Input via Coroutine - Questions & Answers - Unity Discussions

Any help, greatly appreciated!

EDIT: Just adding my comment up here, to state my intentions a bit clearer:

“What I’m trying to create is a terminal-like computer ui, using Unity’s UI system. I have a function called OnEndEdit, which of course is linked to an InputField calling that on OnEndEdit. Would it be possible to use that function to check for input? Thing is, I could call the main menu in the onEndEdit function, and all of this would work, although I would very much like to create different functions for each program that I create, to make further adding of programs simpler!”

A coroutine doesn’t actually halt the execution of code, meaning any statements after your StartCoroutine() call will be executed immediately, regardless of how long your coroutine yields.
The code that you would like to run once your coroutine has finished should be in the actual coroutine method like this:

IEnumerator waitForInput(bool checkThis)
{
   // Wait for the condition to be false
   while (checkThis) yield return null;
   // Put your code here
   Debug.Log("Coroutine finished.");
}

Also note that this coroutine will never stop since the bool parameter is a value type rather than a reference type, meaning the ‘checkThis’ variable will not change even when you assign a new value to ‘inputChanged’.