comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Building an encapsulated library that uses GNAT sockets under Windows
Date: Wed, 27 Apr 2016 22:59:01 -0700
Date: 2016-04-27T22:59:01-07:00	[thread overview]
Message-ID: <nfs8kr$but$1@dont-email.me> (raw)
In-Reply-To: <nfs692$5v7$1@dont-email.me>

On 04/27/2016 10:18 PM, J-P. Rosen wrote:
>
> loop
>    loop
>       {some code}
>       if Found then
>          goto Contine;
>       end if;
>       {some code}
>     end loop;
>     {some code}
> <<Continue>>
> end loop;

People ask for features like a continue statement because they're used to it in 
some other language. I'm not aware of any language that has such a statement 
that exits an inner loop and skips to the end of an outer loop. So I think this 
is a contrived example to try to justify such a statement given that the actual 
uses of the statement in other languages don't justify it. (I hope that makes 
sense.)

Anyway, this can be written as

Outer : loop
    Inner : loop
       {code 1}
       exit Inner when Found;
       {code 2}
    end loop Inner;
    if not Found then
       {code 3}
    end if;
end loop Outer;

I think that is clearer than the goto, and no doubt any efficiency difference 
due to the double evaluation of the condition will be too small to measure. More 
complex cases become

Outer : loop
    Middle : loop
       Inner : loop
          {code 1}
          exit Middle when Found;
          {code 2}
       end loop Inner;
       {code 3}
    end loop Middle;
    if not Found then
       {code 4}
    end if;
end loop Outer;

(I think every loop should have a good name that describes why the loop exists. 
Outer, Middle, and Inner are not such names.)

-- 
Jeff Carter
"We'll make Rock Ridge think it's a chicken
that got caught in a tractor's nuts!"
Blazing Saddles
87


  reply	other threads:[~2016-04-28  5:59 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-21 12:59 Building an encapsulated library that uses GNAT sockets under Windows Dmitry A. Kazakov
2016-04-22  7:58 ` ahlan.marriott
2016-04-22  8:23   ` Dmitry A. Kazakov
2016-04-23  9:20     ` Ahlan
2016-04-23  9:48       ` Dmitry A. Kazakov
2016-04-23 14:45         ` ahlan.marriott
2016-04-23 19:56           ` Dmitry A. Kazakov
2016-04-23 21:16             ` Simon Wright
2016-04-24  8:13               ` ahlan
2016-04-24  8:31                 ` Simon Wright
2016-04-26 19:43                   ` ahlan.marriott
2016-04-26 20:24                     ` Simon Wright
2016-04-26 22:32                     ` Jeffrey R. Carter
2016-04-27 22:16                     ` Randy Brukardt
2016-04-27 23:43                       ` Jeffrey R. Carter
2016-04-28  5:18                         ` J-P. Rosen
2016-04-28  5:59                           ` Jeffrey R. Carter [this message]
2016-05-09 22:32                             ` David Thompson
2016-04-28 20:23                         ` Randy Brukardt
2016-04-28 21:47                           ` Jeffrey R. Carter
2016-04-28  5:13                       ` J-P. Rosen
2016-04-26 20:20               ` Dmitry A. Kazakov
2016-04-26 21:23                 ` Simon Wright
2016-04-27  6:53                   ` Simon Wright
2016-04-27  7:25                     ` ahlan
2016-04-27  8:27                   ` Dmitry A. Kazakov
2016-04-27  9:59                     ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox