How to kill a while loop with a key stroke in Python

Killing a while loop with a key stroke interrupts the executing while loop.

Solution for How to kill a while loop with a key stroke in Python : You can use KeyboardInterrupt to kill a while loop with a keystroke Use a try except statement with the while loop inside of the try block and a Keyboard Interrupt exception in the except statement. When Ctrl-C is pressed on the keyboard, the while loop will terminate.


how-to-kill-a-while-loop-with-a-key-stroke-in-python