[Tutor] try except continue

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Fri Jul 29 01:58:54 CEST 2005

> I see the continue statement as a way for me to do this, and thus
> intimately linked with exception handling.

Hi Tpc,

I think you're getting too caught up with the word "continue" and its
concept as you use it in human language, rather than what it really does
in the Python language.

I should have written an example of 'continue' usage to make things more
explicit.  Here is a simple example:

"""Filters empty lines out of standard input."""
import sys
for line in sys.stdin:
    if not line.strip():
    print line

This is a small program that filters out empty lines from standard input.
The 'continue' statement causes us to immediately jump back to the
beginning of the loop and to keep going.

In Python, continue is intrinstically tied with Python's looping
operations (while/for).


It has very little to do with exception handling, except where the
footnotes mentions certain artificial limitations in using it within an
exception-handling block.

More information about the Tutor mailing list