"Goto" statement in Python

Marko Rauhamaa marko at pacujo.net
Thu Apr 13 11:26:38 EDT 2017


Chris Angelico <rosuav at gmail.com>:

> Personally, I can't remember the last time I yearned for "goto" in
> Python, and the only times I've ever wished for it or used it in other
> languages have been multi-loop breaks or "for...else" blocks. And
> neither is very frequent.

I have occasionally felt the urge to try "goto" in my C code, but having
written it, I have taken it out. It just doesn't make the code look more
elegant or robust. Unlike "break" or "return," "goto" makes me uneasy
about variable scope and lifetime.

Maybe it would work in some state machine implementation. Some 30 years
ago I wrote a compiler. The parser came out nicer with methodical use of
"goto," but even then, I used a parsing-specific macro to wrap it.


Marko



More information about the Python-list mailing list