Python Forum

Full Version: Equivalent of BREAK command
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello folks
I am new to this forum. I hope I am not breaking any posting rules here.
I have been looking at the equivalent of the matlab- BREAK command in python.
My use case is such:
I want to run code line by line and I want to use the break command to terminate the program and not consider anything after the break command.
Please advice .
Vas
You can use sys.exit() for that, or raise SystemExit. However, that is usually done with the control flow of your program.
Thanks Ichabod for the immediate reply...do I have to import any library for this to work?
I trued it and i get this error:

File "C:/Users/Kabali/.spyder-py3/temp.py", line 7, in <module>
sys.exit()

NameError: name 'sys' is not defined

Also ...my intention is such....lets say there is an existing piece of code and i want to "intervene" in the process at a halfway point and play around with the the math part of it or examine values...i want the break command to not run antything AFTER it....even if there is an syntax error or something after the BREAK statement.