comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Labeled exit within generalized labeled loop not allowed?
Date: Mon, 16 Jul 2012 15:03:19 +0300
Date: 2012-07-16T15:03:19+03:00	[thread overview]
Message-ID: <a6ie8cFfi4U1@mid.individual.net> (raw)
In-Reply-To: <a6i90cF82mU1@mid.individual.net>

I forgot to state my conclusion explicitly (at the end, below):

On 12-07-16 13:33 , Niklas Holsti wrote:
> On 12-07-16 12:33 , Thomas L�cke wrote:
>
>> I would've thought that labeled exits were something that were widely
>> used.
>
> A data point on this:
>
> I scanned an Ada 2005 project of mine. It has 893 loops but only 35
> labeled exit statements. These are always on large, complex loops,
> sometimes nested loops where the exit leaves the outermost loop from an
> innner loop. When these loops are traversing a data structure, the
> structure is usually dynamic (e.g. a work-list) that can shrink and grow
> during the execution of the loop.
>
> This project has many loop exits from small traversal loops of fixed
> data structures. These loops could use the generalized loop syntax, but
> the loops are small and usually not nested, so they are not named.
>
> To me, the generalized loop syntax suggests that the loop should be
> executed for all the elements in the container, that the amount of data
> in the container does not change during the loop, and that the traversal
> order is not important. I know that the order is defined; I am talking
> about my impression while reading the program. I'm not sure if data can
> be added to or removed from a container during a generalized iteration
> over the container; would that be "tampering"?

The conclusion is that I (as one example of an Ada programmer) usually 
would not code an exit statement (whether labeled or unlabeled) in a 
simple loop that uses the generalized loop syntax, because then the loop 
would not process all the elements in the container.

Vice versa, I would also be unlikely to use the generalized loop syntax 
for a loop that needs a labeled exit statement, because such a loop is 
likely to be more complex and dynamic than seems suitable (to me) for 
the generalized loop syntax. Moreover, an exit statement usually means 
that iteration order is important, which I (subjectively) do not 
associate with the generalized syntax.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .





  reply	other threads:[~2012-07-24  1:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-13 16:19 Labeled exit within generalized labeled loop not allowed? Marc C
2012-07-13 17:21 ` Thomas Løcke
2012-07-16  9:33 ` Thomas Løcke
2012-07-16 10:33   ` Niklas Holsti
2012-07-16 12:03     ` Niklas Holsti [this message]
2012-07-16 12:29       ` Thomas Løcke
2012-07-16 15:24         ` Marc C
2012-07-17  6:01           ` Thomas Løcke
2012-07-19  6:41       ` Randy Brukardt
replies disabled

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