python "jump" or "goto" commands?

Thomas Wouters thomas at xs4all.net
Wed May 30 19:24:23 EDT 2001


On Wed, May 30, 2001 at 03:14:44PM -0700, eric_brake wrote:

> I'd like to know if python has commands similar to "jump" or "goto".

Nope. _Technically_, the bytecode support is available (because it's
necessary for some other constructs), but there is no way to emit that
bytecode in Python code. The chance that Python will ever grow a 'jump' or
'goto' statement are about as slim as the chance that the entire Python
development team, the PSF and the leftovers of the Python consortium get hit
by a bus in the same day (or, more likely in some of the cases, intoxicated
beyond all recognition within reach of a terminal which happens to be logged
into SourceForge, also all in the same day.)

In Python, you can use a try/except or try/finally block, and raise an
exception, to fake a goto. That's usually the way used to break out of
several layers of loops in an ugly way. I personally find that my code is
doing the wrong thing when I find I need that, though, and a bit of
re-structuring leaves the code overall shorter, faster, cleaner, and without
such hacks :)

> I've been using "while" loops to do the job, but i think if I could
> use a "jump" command it would take less code. And I could also execute
> any part of my code depending on a boolean operator.

Most programmers use an 'if' statement for that, possibly combined with
functions :)

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list