add a stop control to Irremote for a Servo

I programmed the servo to go in a continuous loop which is what I want and now i just want to be able to either pause or stop the servo and am unsure on how to do that. Any help is appreciated, thanks

heres my code-

#include <IRremote.h>
#include <Servo.h>
#define plus 0xFF30CF // We will refer remote control’s “0xFDA857” button as “plus” from now on.
// I will show you where you can find specific codes for your specific remote control.
int RECV_PIN = 11; // Defining Pin 11’s name as “RECV_PIN”.

Servo myservo; // Defining Servo Motor’s name “myservo”.
int val; // Defining rotation angle
bool cwRotation, ccwRotation; // The states of rotation
IRrecv irrecv(RECV_PIN); // Defining IR Receivers Pin Number as “RECV_PIN” which is 11.
decode_results results;

void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Starting the IR Receiver
myservo.attach(8); // Defining Servo Motors Pin Number as 9.
}

void loop()
{
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);

{
myservo.write(0); // Sets the Servo Motors starting position according to the scaled value.
delay(1000); // Waits for half a second before rotating to other direction.
myservo.write(179); // Sets the servo motor’s position to 179 over 180; according to scaled value.
delay(1000); // Waits for 1 second before looping.

}
}
}

    Serial.println(results.value, HEX);

    {
  myservo.write(0);   // Sets the Servo Motors starting position according to the scaled value.
  delay(1000);       // Waits for half a second before rotating to other direction.
  myservo.write(179);   // Sets the servo motor's position to 179 over 180; according to scaled value.
  delay(1000);      // Waits for 1 second before looping.
 
   }

What are the curly braces for? Why doesn't the servo starting to move depend on that the IR receiver received?

During the stickInHeadInSandAndIgnoreTheWorld() calls (mistakenly named delay()), you can not read the IR remote, even if you added calls somewhere to do that.

The loop() function has that name for a reason. Let it handle all the looping. The blink without delay example will show you how to move a servo when it is time to move it again, without calling delay(). You should be able to figure out how to make one button on the IR mean start moving, and another mean stop moving, and only move the servo when it should be moving. Hint: there will be a global boolean variable in your code.

Thank you for your response but I literally learned all this like 2 seconds ago, i have almost 0 clue on what im doing and was just asking for a little help. this code i have here works. all i want is to make the servo stop when i press a different button, and loop control with the one im using now (which ive successfully set up). im stuck on adding the option for another button control and can't find any helpful forums for this purpose.....

If you want a responsive program you have to remove all the delay()s.

The functions delay() and delayMicroseconds() block the Arduino until they complete.
Have a look at how millis() is used to manage timing without blocking in Several Things at a Time.

And see Using millis() for timing. A beginners guide if you need more explanation.

...R