I want to add a Millis timer in place of a for loop

Hello, I am making a state machine in Arduino right now. One of the functions I have currently runs based on number of cycles with a for loop. I want it to run based on time (i.e. instead of running for 300 cycles, run for 30 seconds). I can't seem to get Millis to work. Please help. The specific function is below.

void runStopLongFast ()
{
  enum class simSettings : uint8_t
  {
    IDLE,
    MANUAL,
    CONTINUOUS,
    RUNSTOP,
  };

  static simSettings currMode = simSettings :: RUNSTOP;
    for(int i = 0; i<300; I++)
    {  
    if (digitalRead(manualSwitchA) == HIGH && digitalRead(manualSwitchB) == LOW)
      {
        if (digitalRead(speedSwitch) == LOW && digitalRead(intervalSwitch) == LOW)
        {
          fastCycle();
          Serial.println("In Run-StopLongFast-Cycle");
        }
        else 
        {
          currMode = simSettings :: RUNSTOP;
        }
      }
      else if (digitalRead(manualSwitchA) == HIGH && digitalRead(manualSwitchB) == HIGH)
      {
        currMode = simSettings :: MANUAL;
      }
      else if (digitalRead(manualSwitchA) == LOW && digitalRead(manualSwitchB) == HIGH)
      {
        currMode = simSettings :: CONTINUOUS;
      }
    }      
    for(int i = 0; i<600; I++)
    {  
    if (digitalRead(manualSwitchA) == HIGH && digitalRead(manualSwitchB) == LOW)
      {
        if (digitalRead(speedSwitch) == LOW && digitalRead(intervalSwitch) == LOW)
        {
          digitalWrite(cycleOutput, LOW);    
          delay(50); 
          Serial.println("In Run-StopLongFast-IDLE");
        }
        else 
        {
          currMode = simSettings :: RUNSTOP;
        }
      }
      else if (digitalRead(manualSwitchA) == HIGH && digitalRead(manualSwitchB) == HIGH)
      {
        currMode = simSettings :: MANUAL;
      }
      else if (digitalRead(manualSwitchA) == LOW && digitalRead(manualSwitchB) == HIGH)
      {
        currMode = simSettings :: CONTINUOUS;
      }
    } 
    for(int i = 0; i<1; I++)
    {  
    if (digitalRead(manualSwitchA) == HIGH && digitalRead(manualSwitchB) == LOW)
      {
        if (digitalRead(ad1Switch) == LOW)
        {
          digitalWrite(cycleOutput, HIGH);    
          delay(50); 
          Serial.println("AD1");
        }
        else 
        {
          currMode = simSettings :: RUNSTOP;
        }
      }
      else if (digitalRead(manualSwitchA) == HIGH && digitalRead(manualSwitchB) == HIGH)
      {
        currMode = simSettings :: MANUAL;
      }
      else if (digitalRead(manualSwitchA) == LOW && digitalRead(manualSwitchB) == HIGH)
      {
        currMode = simSettings :: CONTINUOUS;
      }
    }      
    for(int i = 0; i<600; I++)
    {  
    if (digitalRead(manualSwitchA) == HIGH && digitalRead(manualSwitchB) == LOW)
      {
        if (digitalRead(ad1Switch) == LOW)
        {
          digitalWrite(autoDowntime1, HIGH);    
          delay(50); 
          Serial.println("AD1");
        }
        else 
        {
          currMode = simSettings :: RUNSTOP;
        }
      }
      else if (digitalRead(manualSwitchA) == HIGH && digitalRead(manualSwitchB) == HIGH)
      {
        currMode = simSettings :: MANUAL;
      }
      else if (digitalRead(manualSwitchA) == LOW && digitalRead(manualSwitchB) == HIGH)
      {
        currMode = simSettings :: CONTINUOUS;
      }
    }           
}

Welcome! Congratulations on properly posting your code first time.
Wrong place in the forum (should be in Programming...), but that can be fixed by a moderator.

However, I can't tell you what's wrong with what you did with millis(), as I don't see it in your code. Please post that version, much easier to help you with it.

it would also be worth to explain the circuit and context as the code is quite weird..
the typical structure for a state machine would look like this

void runStopLongFast () {
  enum simSettings : uint8_t {IDLE, MANUAL, CONTINUOUS, RUNSTOP};
  static simSettings currMode = RUNSTOP;
  
  switch (currMode) {
    case IDLE:
      ...
      break;

    case MANUAL:
      ...
      break;

    case CONTINUOUS:
      ...
      break;

    case RUNSTOP:
      ...
      break;
  }
}

void setup() {}
void loop() {}

WHY do these loops use "I++" and not "i++"?!?

I would bet They were typed likely outside the IDE with a spell checker on which decided that in English you don’t write a small cap i and turned it into I automatically

That happens to me when typing code directly in the forum

For(int I=… damn autocorrect !

Given the distinction between i and I in C, it is a different variable. Which would imply that, if this code actually compiled, both i and I have been declared. Lethal.

That’s why I think it’s an autocorrect mistake

It happens to me often when I type from my iPhone or iPad

The standard blink without delay-example code makes it unnescessary complicated to understand non-blocking timing.

The main reason is that this example and other tutorials do not focus on the fundamental difference how non-blocking timing works.

You should learn the principle prior to looking into the code.
Knowing the basic principle will make it much easier to understand the code

I recommend a version that puts the details about non-blocking timing into a function
that can be used in a single if-condition that says what the function is doing

checking if TimePeriodIsOver()

if( TimePeriodIsOver(myTimingVariable,Period)  ) {
  // do timed action
}

best regards Stefan