"Goto" statement in Python

Mikhail V mikhailwas at gmail.com
Thu Apr 13 12:23:57 EDT 2017


On 13 April 2017 at 02:17, Rob Gaddi <rgaddi at highlandtechnology.invalid> wrote:

>
> def finder:
>   for s in S:
>     if s == 'i':
>       return 'found on stage 1'
>
>   S = S + ' hello world'
>   for s in S:
>     if s == 'd':
>       return 'found on stage 2'
>
>   raise ValueError('not found; S=' + S)
>
> try:
>   message = finder()
>   print(message)
>   log += message
> except ValueError as e:
>   print(e)
>

Mother of God... This is like placing some abstract art into a gallery
of monumentalism art.
I am upset and need some healing therapy now.
I'll stay here  for a while:
https://www.pinterest.com/soren19/arqbrt/


On 13 April 2017 at 13:31, alister <alister.ware at ntlworld.com> wrote:
>
> I expect you could simulate most of these with a custom exception
> for example break from nested loop:
>
> class GoTo(Exception):
>     pass
>
> try:
>     for i in range(100):
>         print i
>         for j in range (50):
>             print j
>             if i*j>60:
>                 raise GoTo
> except GoTo:
>     print "Exit Early"
> print "end of loop"
>

Now I wonder, have we already collected *all* bells and whistles of Python
in these two examples, or is there something else for expressing trivial thing.


Mikhail



More information about the Python-list mailing list