On Thu, 13 Nov 2008 11:07:25 +0100, TP wrote:

> According to this page, the best way is to modify the loop by affecting
> the variables that are tested in the loops. Otherwise, use exception:
> 
> "If, for some reason, the terminating conditions can't be worked out,
> exceptions are a fall-back plan."
> 
> In the following example, is this possible to affect the two iterators
> to escape the two loops once one "j" has been printed:
> 
> for i in range(5):
>     for j in range(i):
>        print j
>        # I would type "break 2" in shell bash # In C, I would set j=i-1
>        and i=4
>        # In Python, is this possible to affect the two iterators?
> 
> Or the only means is to use exception?

You could put the code into its own, maybe local, function and use 
``return``.

Ciao,
        Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to