Loop in custom function before returning to void loop ()

Hello,
I am learning basic modules, controls and programming of Arduino. I am building my first project with IR remote.

IDEA:
IR CAR. Car will have couple functions.

  1. Controlling car with IR remote
  2. Car avoides obscticles
  3. Car attacks obsticles
  4. Back to Meniu

I want to be able to switch these functions with IR remote. Lets say if button 1 is pressed I want to control car with my remote while button 4 isn't pushed. When button 4 is pushed I want to return to meniu and choose another function.

CODE:

void loop()
     if (irrecv.decode(&results))
      Serial.println(results.value); 
      switch (results.value) 
         case 16753245:  // button 1 is pressed
            IR_control();
            break; 
         
         }      
   irrecv.resume(); 
   }
}

void IR_control()
{
      digitalWrite(LED_YELLOW, HIGH);
       if (irrecv.decode(&results)) 
     {
      Serial.println(results.value); 
      
      switch (results.value) 
      { 
        
         case 16718055:  //Move forward
            forward(); 
            break; 
         case 16730805:  //Move back
            back();
            break;
         }      
   irrecv.resume(); 
   }
}

void forward()
{
       digitalWrite(8, HIGH);
       digitalWrite(9, LOW);
       digitalWrite(10, HIGH);
       digitalWrite(11, LOW);
}
void back()
{
        digitalWrite(8, LOW);
        digitalWrite(9, HIGH);
        digitalWrite(10, LOW);
        digitalWrite(11, HIGH);
}

PROBLEM: Currently my program only runs once through function void IR_control() and returns to void loop() but I want it to stay in void IR_control() while button 4 isn't pressed.

Any ideas how I should implement this? I thought about while() in the void IR_control() function, but void loop() would still loop.

robo_hobby:
PROBLEM: Currently my program only runs once through function void IR_control() and returns to void loop() but I want it to stay in void IR_control() while button 4 isn't pressed.

Don't call the IR_control() function directly (as you are currently doing). Instead use the 4 buttons to update a variable that defines what state the system is working in, For example if you press button1 you could set the variable (let's call it controlState) to 'R' (for remote).

Then in loop (after all of your IR code) you could have code like this

if (controlState == 'R') {
   IR_control();
}
else if (controlState == 'A') { // A for avoidance
  // call the avoid function
}
// etc

The purpose of this approach is so that the Arduino remembers the state that has been chosen

...R

This fits perfectly. Thank your for your time.