Press Spacebar to let it run, and press S to make it stop part-way through.
Thanks to Mr. Flannigan for the inspiration of the code for this, his version showed me the basic idea of how to do this.