Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Since load("script.sage") basically has the same effect as executing the code in the file as if typed in at the prompt, I think your question is just a matter of "how do l let a piece of python code end its execution and return control to the point of invocation. So, all regular python flow control structures are at your disposal. sys.exit() should work in sage but it doesn't do what you ask: it will end the sage session.

If you need to break out of a single for or while loop, you can use break. Python does not provide multi-level breaks, so if you need to break out of more complicated flow control, it's probably easiest to place the entire procedure in a function and use return.