Loops Control with Python

Scott David Daniels scott.daniels at acm.org
Fri Oct 13 17:53:45 CEST 2006


Wijaya Edward wrote:
> Can we make loops control in Python? What I mean is that whether
> we can control which loops to exit/skip at the given scope.
> For example in Perl we can do something like:
>   OUT:
>   foreach my $s1 ( 0 ...100) {
>       IN:
>       foreach my $s2 (@array) {
>             if ($s1 == $s2) {
>                next OUT;
>             }
>             else {
>                 last IN; 
>             } 
>        }
>   }
> How can we implement that construct with Python?

If you are not willing to determine the problem the code is
written to solve, you are doomed to working with "Perl in Python".
While I think Python is a far better language than Perl, I remain
convinced that Perl is a better Perl than Python.  Describe an
actual problem, don't simply give an example from another language.

If you don't know about break, continue, and for ... else, go
study the Python language.

-- 
--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list