If "STOP" Is typed do this
No - Applescript is not multi-threaded in the sense that you can set up two things to happen at one time.

To do what you want, you'd need another language that could open a window so the user could type characters to be interpreted and change the signal variable to exit the loop. That language would handle multiple threads and communication between the two processes so that the setting of the new X value would be visible to the other thread running the loop.

If you'd rather stick to AppleScript, you could probably do what you want by using the existence of a file to keep the loop running:

if file "semaphore" of application "Finder" exists then
   -- continue processing...
end if


This is documented at https://developer.apple.com/library/mac/documentation/AppleScript/Conceptual/AppleScriptLangGuide/conceptual/ASLR_fundamentals.html

Search for the section titled Direct Parameter or use the semaphore string to locate the snippet I copied above. Then you could have the user delete the "chosen" file - maybe putting it on their desktop and call it "keepRunning" or something so they trash it when the script should stop running.