ir remote problem , how to press stop button to stop count at for loop??

hi dear, my problem is i press stop button from my remote , the continue still continue counting? how to stop it if i wan before counting number to 9999? can i skip count , i wan exit when i press my remote control exit key? how the sketch i write? pls help

#include "IRremote.h"

int RECV_PIN = 2;
decode_results results;
IRrecv irrecv(RECV_PIN);
unsigned long val;

int ledpin = 13;

#define leftkey 0xFF10EF
#define rightkey 0xFF5AA5

int count = 0;

String x = "";
int y = 0;

void setup() {
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(ledpin,OUTPUT);
// digitalWrite(ledpin,HIGH);
}

void loop() {
if (irrecv.decode(&results)){
val = results.value;
Serial.println(val);
irrecv.resume(); // important return
switch (results.value){
case leftkey:
digitalWrite(ledpin,HIGH);
Serial.println("Led On");
Counter();
Serial.print(count);
break;

case rightkey:
digitalWrite(ledpin,LOW);
Serial.println("Led off");
break;

}
}
}

void Counter(){

y = x.toInt();
for (int i = y; i <= 9999; i++) {
Serial.print("Remaining Time:");
Serial.print(i, DEC);

}
}

Don't use a for loop to do the counting, let the loop() function do it for you. That way you can do other things in loop() such as reading inputs

Why is x a String and why does its value never get changed ?

actually i wan write code for tm1637 7segment display, use a x string to use remote control enter a number and press start, to start counting, and press to stop button to stop counting, and press clear button to clear number to 0000, and enter again.

OK, but why is x a String when it is really a number ?