Timing Troubles

Hello,
I have a circuit set up with a button and an RGB LED. I would like the LED to change colors when I press the button, however, only when the button is pressed for more than 3 seconds. Also, I would like this to only happen once. My attempt is below, however it did not work for me. Any suggestions?

const int button = 2;
const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;
int buttonState = 0;
bool triggered = false;

void setup() {
  pinMode(2, INPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);

  Serial.begin(9600);
  setColor(0, 255, 0);
}

void loop() {
  bailout:
  
  do{
    buttonState = digitalRead(button);

    if(buttonState == HIGH){
      int i = 0;
      
      for(i = 0; i <= 30; i++){
        buttonState = digitalRead(button);
          if(buttonState == LOW){
            Serial.println("The button wasn't pressed long enough");
            goto bailout;
          }
          delay(100);
       }
      setColor(255, 0, 0);
      Serial.println("The button was pressed for > 3 seconds!");
      triggered = true;
    }
  }while(triggered == false);
}

void setColor(int red, int green, int blue){
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);
}

a goto statement? Yikes!!!!

Look at the BlinkWithoutDelay example (File->Example->02.Digital->BlinkWithoutDelay) to see how to do timing of events.

Look at the StateChangeDetection example to see how to detect when your button changes state. That is the time to start/stop your timer. You don't really care about the current state of the button.

Since you are new, how is your button wired up? Typically, one side is wired to ground and the other side wired to an input pin. This reverses the logic (LOW == pressed, HIGH == not pressed) and you have to set the pin as INPUT_PULLUP in your setup() function.

You also have to declare your RGB pins as OUTPUT in setup()

void setup() {
  Serial.begin(9600);
  pinMode( button, INPUT_PULLUP);
  pinMode( redPin, OUTPUT );
  pinMode( greenPin, OUTPUT );
  pinMode( bluePin, OUTPUT );
}

Thank you for the examples, i've read BlinkWithoutDelay and StateChangeDetection. I see where i could improve the button detection and counter. No need for the input_pullup as i have the button wired with one end at 5V, the other at a 10K resistor to ground, and pin 2 connected between the button and the resistor. I'll be replacing the button with a magnetic sensor, thus the need for some type of timer to prevent false positives.

(deleted)