Making my if statement repeat until remote button is pressed again

#include <Servo.h>
#include <IRremote.h>

int IRpin = 10; // pin for the IR sensor

IRrecv irrecv(IRpin);
decode_results results;

Servo myservo;
// create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position

void setup() {
myservo.attach(9);
pinMode(5,OUTPUT);
irrecv.enableIRIn();

// attaches the servo on pin 9 to the servo object
}

void loop() { if (irrecv.decode(&results))
{

irrecv.resume(); // Receive the next value
}

if (results.value == 16724175){

digitalWrite(5,HIGH);

for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15);
// waits 15ms for the servo to reach the position
}}
}

Please read https://forum.arduino.cc/index.php?topic=148850.0. Please pay specific attention to point #7 about posting code so your code looks like below

#include <Servo.h>
#include <IRremote.h>


int IRpin = 10;  // pin for the IR sensor

IRrecv irrecv(IRpin);
decode_results results;

Servo myservo;
// create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);
  pinMode(5,OUTPUT);
  irrecv.enableIRIn();
 
  // attaches the servo on pin 9 to the servo object
}

void loop() { if (irrecv.decode(&results))
    {
     
      irrecv.resume();   // Receive the next value
    }
   
   
   if (results.value == 16724175){

  digitalWrite(5,HIGH);

  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);
    // waits 15ms for the servo to reach the position
  }}
}

Before you post code, please properly indent it in the IDE using tools->autoformat (not done above).

Regarding your ‘problem’, I suggest that you keep a flag that you toggle when the button is pressed. It could look like below (not tested).

void loop()
{
  static bool flag = false;
  if (irrecv.decode(&results))
  {
    if (results.value == 16724175)
    {
      flag = !flag;
    }

    irrecv.resume();   // Receive the next value
  }


  if (flag == true)
  {
      digitalWrite(5, HIGH);

      ...
      ...
  }
}

Now that you have been PROPERLY and RIGHTFULLY scolded for posting unformatted code … here is my favorite way to handle button presses on Arduino’s. If you are using a standard UNO or compatible (nano etc.) then this should work fine… the EnableInterrupt library can conflict with other libraries depending on how you’re using your interrupts on your arduino but from what I see here, it should work just fine. Just make sure one side of the button is connected to ground and the other side to whichever pin you’re using to detect the button press. And you’ll have to add the EnableInterrupt library to you’re Arduino software but that’s pretty easy to do in the library manager.

#include <Arduino.h>
#include <EnableInterrupt.h>


long last_interrupt_time1;
const int Button1Pin = 7;
#define DEBOUNCE_DELAY 150
bool button1Pressed = false;


void b1Handler(){
    uint32_t interrupt_time = millis();
    if (interrupt_time - last_interrupt_time1 > DEBOUNCE_DELAY) {
        button1Pressed = true;
    }
    last_interrupt_time1 = interrupt_time;
}


void setup() {
    pinMode(Button1Pin,INPUT_PULLUP);
    enableInterrupt(Button1Pin, b1Handler, FALLING);
}

void loop()
{
    while (!button1Pressed) {
        
        // This is the code loop that is waiting for the button to be pressed.
        // The code will IMMEDIATELY be interrupted and this loop will stop when
        // the button is pressed, bucause the button will be triggering a hardware
        // interrupt and the interrupt handler will simply set a boolean variable
        // that lets me know the button was pressed.
    }
    
    
    // Here, the loop is over and we need to reset that trigger flag

    button1Pressed = false;
}