For Loop restarting early. Iteration variable restarting while loop condition is still true.

My For loop is ending early. It’s ending even thought the loop condition is still true:

        for (int i = 0; i < currentText.Length; i++) {
            if (optionLines == null && currentText*.Contains("option"))*

arrayLength++;

if (i == currentText.Length - 1)
optionLines = new int[arrayLength];
}
currentText.Length is 24, however after variable i is equal to 21 it becomes 0. Why is this happening? The variable i should get to 23 before it restarts and turns into 0 again.

Sanity check it. I doubt that is what is happening. Do you have any script errors? Fix those.

Debug.Log("currentText.Length: " + currentText.Length);

Put this before and inside the for loop to keep track of the length, or attach a debugger. If it changes length, look at all code that references the variable/object and see what could possibly change its size.