"Goto" statement in Python

bartc bc at freeuk.com
Thu Apr 13 18:59:25 EDT 2017


On 13/04/2017 22:58, Ian Kelly wrote:
> On Thu, Apr 13, 2017 at 3:27 PM, Dennis Lee Bieber
> <wlfraed at ix.netcom.com> wrote:
>> On Thu, 13 Apr 2017 15:52:24 +0100, bartc <bc at freeuk.com> declaimed the
>> following:
>>
>>> 'goto' would be one easy-to-execute byte-code; no variables, objects or
>>> types to worry about. If implemented properly (with the byte-code
>>> compiler using a dedicated name-space for labels) there would be no name
>>> lookups.
>>>
>>
>>         Only if GOTO is not allowed to break out of namespaces...
>>
>>         NO GOTO from inside a function to some global catch-all handler...

(That doesn't happen. No sane language would allow it, not on the 
user-side anyway.)

>>         Once you permit uncontrolled/unlimited GOTO you have to be concerned
>> with stack-frames and object life-times.
>
> Even within a function you would still have to be concerned about a
> goto from inside a try or with block to outside of that block, as the
> finally block or the context manager's __exit__ still need to be
> executed on the way out.

So how does 'break' manage it? I assume break works from inside a try- 
or with-block.

Jumping /into/ such a block might be more tricky, but it is simple 
enough to not allow it.

-- 
Bartc


More information about the Python-list mailing list