how to exit counting Ir remote code, pls help

please help , ir remote how to press up counter for start counting , press down button to quit exit counting, i cannot get exit code, any one can help?

#include "IRremote.h"

int RECV_PIN = 2;
int led = 13;
decode_results results;
unsigned long key_value = 0;
IRrecv irrecv(RECV_PIN);

#define TEST_DELAY 200
#define UP_DELAY 10
#define HOLD_DELAY 150

#define Up 0xFF18E7
#define Down 0xFF4AB5
#define RightArrow 0xFF5AA5
#define LeftArrow 0xFF10EF
#define OKButton 0xFF38C7
#define StarSign 0xFF6897
#define HSign 0xFFB04F
#define One 0xFFA25D
#define Two 0xFF629D
#define Three 0xFFE21D
#define Four 0xFF22DD
#define Five 0xFF02FD
#define Six 0xFFC23D
#define Seven 0xFFE01F
#define Eight 0xFFA857
#define Nine 0xFF906F
#define Zero 0xFF9867

void setup() {
Serial.begin(9600);
irrecv.enableIRIn();

}

String x ="1000";
int y=0;

void loop(){
if (irrecv.decode(&results)){
if (results.value == 0XFFFFFFFF)
results.value = key_value;

switch(results.value){
case Up:
y = x.toInt();
for (int i = y; i <= 9999; i++) {
Serial.print("Remaining Time:");
Serial.print(i, DEC);
// display.showNumberDec(i,DEC);
delay(1000);
}
case Down:
break;
}

key_value = results.value;
irrecv.resume();

}
}

hello, the code continues run in for loop, i wan press ir remote to stop counting in for loop, any one can helps?
thank you

jimmycks:
please help , ir remote how to press up counter for start counting , press down button to quit exit counting, i cannot get exit code, any one can help?

    switch (results.value)

{
      case Up:
        y = x.toInt();
        for (int i = y; i <= 9999; i++)
        {
          Serial.print("Remaining Time:");
          Serial.print(i, DEC);
          //      display.showNumberDec(i,DEC);
          delay(1000);
        }
      case Down:
        break;
    }

The Arduino can only do one thing at a time. While it is running your 'for' loop it can't also look for new input from the remote control. You have to do your counting separately from your checking for remote input. Use the "BlinkWithoutDelay" example to make your counter count once per second and use the irRecv only to set a flag to indicate if the counter should be counting or not.

    switch (results.value)
    {
      case Up:
        Counting = true;
        break;

      case Down:
        Counting = false;
        break;
    }

thank you, johnwasser thank for help, i will try it with false and true mode