IR Receive Input while in for loop

I’m trying to get a neopixel led strip (clone) working with an IR remote using the IRremote library at GitHub (https://github.com/z3t0/Arduino-IRremote).

I have it so it will cycle through colors but would like to have different “modes”. For example button 1 will make a rainbow, button 2 will do a “walking” color change.

The problem seems to be that I can’t get the IR to receive when in a while/for loop. The code compiles and runs fine, just locked out of receiving input during the loop.

Has anybody figured out how to “peek” or allow IR signals to still be detected while in a loop?
thanks and sorry if this is a noob question.

void loop() {
  
   if (irrecv.decode(&results)) {
    lReceived = results.value;
   
  switch (lReceived) {
    case button1:
      Serial.println("button1 pressed");
      if(!isOn)
      {
        int numtimesrun = 2;
        int currtimesrun = 0;
        isOn = true;        
        do
        {
          
          if(currtimesrun == numtimesrun)
          {
              Serial.println("sees done");
               for (i=0; i < strip.numPixels(); i++) {
                  strip.setPixelColor(i, 0,0,0);
               }
               strip.show();   // write all the pixels out

            isOn = false;
          }
          for (j=0; j < 256; j++) {     // 3 cycles of all 256 colors in the wheel              
            if(!isOn)
            {
              return;
            }                      
            
            for (i=0; i < strip.numPixels(); i++) {
              strip.setPixelColor(i, Wheel( (i + j) % 255));              
            }  
            strip.show();   // write all the pixels out
            irrecv.resume(); // Receive the next value            
            delay(20);   
          }
          Serial.println("after loop");          
          ++currtimesrun;
        }
        while(isOn);
                
        isOn = false;
        //rainbow(20);
      }             
      break;
    case button2:
      Serial.println("button2 pressed");
      while (isOn == true){
        rainbowCycle(20);
      } 
      break;
    case button3:
      break;
    case button4:
       Serial.println(4);
      break;
    case button5:
      Serial.println(5);
      break;
    case button6:
       Serial.println(6);
      break;
    case button7:
       Serial.println(7);
       break;
    case button8:
       Serial.println(8);
      break;
    case button9:
       Serial.println(9);
      break;
    case buttonPausePlay:
      isPaused = true;
      Serial.println("true");
      break;
    case buttonEQ:
      isOn = false;
      Serial.println("false");
      break;
      }
      irrecv.resume(); // Receive the next value
   }
 }

Has anybody figured out how to "peek" or allow IR signals to still be detected while in a loop?

Well, you could put the IR read inside the while loop, but a better solution is not to use a while loop in the first place.

Instead, when in a particular case then execute one step of what was originally in the while loop each time through the loop() function. You can then read the IR in loop() and change case if an appropriate input is received.