"Goto" statement in Python

Bernd Nawothnig Bernd.Nawothnig at t-online.de
Fri Apr 14 09:43:54 EDT 2017


On 2017-04-13, Grant Edwards wrote:
> On 2017-04-13, Rob Gaddi <rgaddi at highlandtechnology.invalid> wrote:
>
>> No, C doesn't support exception handling.  As a result, handling error 
>> conditions in C is a huge pain for which (forward-only) goto is often, 
>> while not the only remedy, the least painful one.
>
> Indeed. That is almost the only place I use 'goto' in C, and the
> almost the only place I see others use it.  Very occasionally, you see
> a the error handling goto refactored into a backwards "goto retry":
>
> this code
>
> foo()
>   {
>   while (1)
>     {
>       <some code>
>       if (<some-error-condition>)
>            goto error:
>       <more code>
>       return;
>
>     error:
>       <recover-from-error-condition>
>     }
>   }

foo()
  {
  int done = 0;
  while (! done)
    {
      <some code>
      if (<some-error-condition>) {
        <recover-from-error-condition>
      } else {
        done = 1;
        <more code>
     }
  }




Bernd

-- 
Die Antisemiten vergeben es den Juden nicht, dass die Juden ‘Geist’
haben – und Geld. Die Antisemiten – ein Name der
‘Schlechtweggekommenenen’ [Friedrich Nietzsche]


More information about the Python-list mailing list