Working around a lack of 'goto' in python

Carmine Noviello cnoviello at hotmail.com
Sat Mar 6 13:41:20 EST 2004


> (1) deeply nested loops
>
> for (k=0; k < 10; ++k)
> for (j=0; j < 10; ++j)
> for (i=0; i <10; ++i)
>     if (/* some test */) goto END;

done = 0
while k < 10 and not done:
     k += 1
     while j < 10 and not done:
         j+=1
         while i < 10 and not done:
              i+=1
              if /*some test*/: done = 1


> and (2) repeating a while or for loop from the beginning:
>
> BEGIN:
> for (n=0; n < 20; ++n)
>     if (/* some test */) goto BEGIN;
>

while n < 20:
    if /*some test*/: n = 0

There is always a way to not use "goto".

-- 
Don't you know why your Python application has crashed?
Take a look to http://www.pycrash.org
My Home Page http://cnoviello.altervista.org





More information about the Python-list mailing list