Working around a lack of 'goto' in python

Brett abc at def.net
Sat Mar 6 13:18:28 EST 2004


Two areas where I've found 'goto' two be useful in other languages are in
(untested examples in C++)

(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;

END: /* continue */;

and (2) repeating a while or for loop from the beginning:

BEGIN:
for (n=0; n < 20; ++n)
    if (/* some test */) goto BEGIN;

What are the techniques in python for simulating these algorithms without a
'goto' command?

Thanks.






More information about the Python-list mailing list