Problem between IEnumerator Enumarator(){} and vand void OnGui(){}

Good day community, I got the next blocks of code. The first one is being called from void OnGUI() {} and the second one too, by pressing a button, but it’s an IEnumerator.

void MessageWindowComponents(int winndowID)
    {
        GUI.Box(new Rect(10.0f, 25.0f, messageWindow.width - 20.0f, messageWindow.height - 70.0f), _message);
        if (GUI.Button(new Rect(60.0f, 165.0f, 80.0f, 23.0f), "Accept"))
        {
            if (replaceRack)
            {
                replaceRack0 = 1;
                Debug.Log("I was here0");
                Debug.Log(replaceRack0.ToString()); // <--- replaceRack0 changes to 1
            }
            messageWindowEnabled = false;
            _message = "";
        }
        if (GUI.Button(new Rect(160.0f, 165.0f, 80.0f, 23.0f), "Cancel"))
        {
            if (replaceRack)
            {
                replaceRack0 = 2;
                Debug.Log("I was here1");
                Debug.Log(replaceRack0.ToString()); // <--- replaceRack0 changes to 2
            }
            messageWindowEnabled = false;
            _message = "";
        }
    }
IEnumerator LoadRackFromJsonFile(JsonData jsonData)
    {
        int index = 0;
        bool allowCreateRack = true;
        while (index < jsonData.Count)
        {
            double[] doubles = new double[7];
            for (int i = 4; i < 11; i++)
            {
                doubles[i - 4] = double.Parse(jsonData[index][i].ToString());
            }
            Vector3 position = new Vector3((float)doubles[0], (float)doubles[1], (float)doubles[2]);
            Quaternion rotation = new Quaternion((float)doubles[4], (float)doubles[5], (float)doubles[6], (float)doubles[3]);
            bool isAvailable = false;
            if (jsonData[index]["isAvailable"].ToString() == "True")
            {
                isAvailable = true;
            }

            if (rackList.Count > 0)
            {
                if (replaceRack0 == 0) // <--- This should change
                {
                    for (int k = 0; k < rackList.Count; k++)
                    {
                        if (rackList[k] != null)
                        {
                            if (index < jsonData.Count)
                            {
                                if (string.Equals(rackList[k].name, jsonData[index]["name"].ToString()))
                                {
                                    _message = "\n\nRack '" + rackList[k].name + "' is already registered,\nwould you like to override it?";
                                    messageWindowEnabled = true;
                                    replaceRack = true;
                                    allowCreateRack = false;
                                    break;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                else if (replaceRack0 == 1) // <--- This should change
                {
                    for (int k = 0; k < rackList.Count; k++)
                    {
                        if (rackList[k] != null)
                        {
                            if (index < jsonData.Count)
                            {
                                if (string.Equals(rackList[k].name, jsonData[index]["name"].ToString()))
                                {
                                    Destroy(rackList[k]);
                                    break;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    CreateRackFronJson(jsonData, index, isAvailable, position, rotation);
                    index++;
                    replaceRack0 = 0;
                } else if (replaceRack0 == 2) // <--- This should change
                {
                    index++;
                    replaceRack0 = 0;
                }
                if (allowCreateRack)
                {
                    CreateRackFronJson(jsonData, index, isAvailable, position, rotation);
                    index++;
                    replaceRack0 = 0;
                }
            }
            else if (rackList.Count == 0)
            {
                if (index < jsonData.Count)
                {
                    CreateRackFronJson(jsonData, index, isAvailable, position, rotation);
                    index++;
                    replaceRack0 = 0;
                }
            }
            Debug.Log(replaceRack0.ToString()); //<--- replaceRack0 is always 0
            yield return null;
        }
    }

The idea here is when I find an item on a list with the same name, a window pops up saying that there is already an item with a name and then It will let me choose if I want to replace the object or no, so I created a variable called replaceRack0 which is set to 0 at the beginning, meaning that no option has been chosen yet, when it is set to 1, the object will be overridden, and if set to 2, object shall not be overridden.

I put 3 Debug.LOG(); to see the value of the variable, problem is that it changes on click of the buttons, but it is not updated inside the IEnumarator method.

Is there any solution to this?

IEnumerator LoadRackFromJsonFile(JsonData jsonData)
    {
        int index = 0;
        bool allowCreateRack = true;
        while (index < jsonData.Count)
        {
            double[] doubles = new double[7];
            for (int i = 4; i < 11; i++)
            {
                doubles[i - 4] = double.Parse(jsonData[index][i].ToString());
            }
            Vector3 position = new Vector3((float)doubles[0], (float)doubles[1], (float)doubles[2]);
            Quaternion rotation = new Quaternion((float)doubles[4], (float)doubles[5], (float)doubles[6], (float)doubles[3]);
            bool isAvailable = false;
            if (jsonData[index]["isAvailable"].ToString() == "True")
            {
                isAvailable = true;
            }

            if (rackList.Count > 0)
            {
                if (replaceRack0 == 0)
                {
                    for (int k = 0; k < rackList.Count; k++)
                    {
                        if (rackList[k] != null)
                        {
                            if (index < jsonData.Count)
                            {
                                if (string.Equals(rackList[k].name, jsonData[index]["name"].ToString()))
                                {
                                    _message = "\n\nRack '" + rackList[k].name + "' is already registered,\nwould you like to override it?";
                                    messageWindowEnabled = true;
                                    replaceRack = true;
                                    allowCreateRack = false;
                                    break;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                else if (replaceRack0 == 1)
                {
                    for (int k = 0; k < rackList.Count; k++)
                    {
                        if (rackList[k] != null)
                        {
                            if (index < jsonData.Count)
                            {
                                if (string.Equals(rackList[k].name, jsonData[index]["name"].ToString()))
                                {
                                    Destroy(rackList[k]);
                                    break;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    CreateRackFronJson(jsonData, index, isAvailable, position, rotation);
                    index++;
                    replaceRack0 = 0;
                    allowCreateRack = true; // <--- Solution!
                } else if (replaceRack0 == 2)
                {
                    index++;
                    replaceRack0 = 0;
                    allowCreateRack = true;
                }
                if (allowCreateRack)
                {
                    CreateRackFronJson(jsonData, index, isAvailable, position, rotation);
                    index++;
                    replaceRack0 = 0;
                    allowCreateRack = true; // <--- Solution!
                }
            }
            else if (rackList.Count == 0)
            {
                if (index < jsonData.Count)
                {
                    CreateRackFronJson(jsonData, index, isAvailable, position, rotation);
                    index++;
                    replaceRack0 = 0;
                    allowCreateRack = true; // <--- Solution!
                }
            }
            //Debug.Log(replaceRack0.ToString());
            yield return null;
        }
    }

Nevermind, the solution was to set the allowCreateRack varaible to true at the end of each if statement.