How can I stop an RGB LED from cycling?

I have the following code I use to cycle an RGB LED through its colors but I would really like to be able to press a button or a switch to make it stop/go and stay that color. How can I go about doing this with the following code that I have? Thanks in advance.

const int redPin = 11;
const int greenPin = 10;
const int bluePin = 9;

void setup() {
  // Start off with the LED off.
  setColourRgb(0,0,0);
}

void loop() {
  unsigned int rgbColour[3];

  // Start off with red.
  rgbColour[0] = 255;
  rgbColour[1] = 0;
  rgbColour[2] = 0;  

  // Choose the colours to increment and decrement.
  for (int decColour = 0; decColour < 3; decColour += 1) {
    int incColour = decColour == 2 ? 0 : decColour + 1;

    // cross-fade the two colours.
    for(int i = 0; i < 255; i += 1) {
      rgbColour[decColour] -= 1;
      rgbColour[incColour] += 1;
      
      setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);
      delay(5);
    }
  }
}

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

make loop() a sub-function to be called conditionally based on a integer flag that is toggled when a button is pressed. presumably you understand how to check for the change in state of a button and recognize that when changed and if low, the button was pressed.

look at the State Change Detection example in the IDE. That will show you how to to properly handle a button press. When it happens, set a flag. When it happens again, reset the flag.

Based on the flag, execute the next step in your color sequence. You can not simply make your loop() code into another function and call it since you do not want it to run through the entire for() loops you have. Only have it do one step and then return so loop() can check the button again,...

gcjr:
make loop() a sub-function to be called conditionally based on a integer flag that is toggled when a button is pressed. presumably you understand how to check for the change in state of a button and recognize that when changed and if low, the button was pressed.

Although I don't know much of coding, I fully understood all this, so now I just have to loop up how to code this. Learning as I go, thanks for the replies!