(Aug-06-2021, 05:38 PM)jefsummers Wrote: Another option is wrapping in a try/except block and raising an exception. You could just raise without the try except if you dont mind seeing the traceback
try: for i in range(5): print(i) if i == 3: raise UserWarning('Exit Early') print('foobar') except: pass
The exception is fine for me since I'm doing this for debugging purposes. It's not user-friendly, though, and there are plenty of instances where this should be useful--the most common being "do you wish to continue?"
This isn't an issue if it's the end of the code because nothing comes next and the code ends. If it's in the middle of the code then I see a void without some sort of statement that can do this. Also, AFAIK Python isn't like some other languages (BASIC, VBA) where you can have a "Goto" line that takes the program to the end for such purpose.
I feel like there's an important concept regarding all this that I have yet to learn.