Breaking into a loop to stop it

I have a set of strip leds that lights up when a certain serial value is received, and stay on for a certain number of loops determined by a counter.

What I'd like to happen is that if at any time while it's going through the loop, if it gets a different value from the serial input, the lights turn off - the problem is of course that while it's going through the loop, it's not looking for a change in the serial value. I'm assuming that I can have it look for a change of the serial input value while its going through the loop instructions to send it back to the top of the main loop if its sees a new value - just not sure if that's the right approach and how to do that. Any help would be appreciated.

In my code below, if the system reads a letter "V" from the serial value, it goes through the "solidred" loop, coloring all the leds red. I'd like it so that any time during the loop, it looks at the serial input and if it sees the letter "O" it will stop.

Code to look for the V in the main loop of the sketch:

 if (val == 'V' and oldval != val) { // 
     solidred();

Loop for solid red lights:

 //SOLID RED
 void solidred() {
 while (counter<1000){
for (int i=0;i<NUM_LEDS;i++){
  leds[i] = CRGB::Red;
  FastLED.show();
    //Serial.print (counter);
  counter++;
  }

Can you show your entire sketch?

Why do you keep setting the LEDs to red? Don't they stay the color you set them until you set them to another color?

You need to remove the while loop and let that be handled by iterating the main loop. You can keep a count there. This way, you can first check the serial and depending on whether the leds are already on or off do some actions.

If you have to "break into a loop" then you should not have a loop in the first place.

Have a look at how things are done in Several Things at a Time

Note how each function runs very briefly and returns to loop() so the next one can be called. And there may be dozens of calls to a function before it is actually time for it to do anything.

...R