comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Dewar <robert_dewar@my-deja.com>
Subject: Re: checking a loop execution
Date: 2000/04/21
Date: 2000-04-21T00:00:00+00:00	[thread overview]
Message-ID: <8do7b2$p8h$1@nnrp1.deja.com> (raw)
In-Reply-To: 38fece05.0@silver.truman.edu

In article <38fece05.0@silver.truman.edu>,
  "chad" <crmeiners@hotmail.com> wrote:
> The following code does what you want:
>
>   declare
>       Index      : Integer := 1;
>       Interupted : Boolean := False;
>   begin
>
>       loop
>
>           Interupted := <Condition>;

I find the use of boolean variables like this annoying
obfuscation in many cases. I would not mind at all using
a goto for this special case of a loop with multiple exits.
Some languages have a special construct for this, but if
this is lacking, then really the goto is as clear as anything
and avoids duplicating a test.

Yes, I know some people get the heebie-jeebies when they
see a goto, but just remember you weren't born this way,
it is learned behavior, and it can be unlearned. Almost
every style rule should be considered as a guide, and the
really skilled programmer is one who does not have to rely
on absolute rules like "Never use a goto", and instead knows
enough to discriminate.

Code like

for J in 1.. 10 loop
   if Condition then goto Loop_Interrupted;
   ....
end loop;

--  Here if loop ends normally

...
return;

--  Here if loop ends abnormally

<<Loop_Interrupted>>
...
return;


reads quite clearly to me, and I would be surprised and a
bit puzzled by any programmer to whom it did NOT read
clearly.

And as someone pointed out, if the interrupted section is
short, you can simply put it right in the loop (of course
a return from the middle of a scope is also a goto, but
often an acceptable one -- the amusing thing is people who
hate *all* gotos, but don't recognize that statements like
return are gotos :-)

I think I mentioned before running into a COBOL programmer
who hated gotos but had no hesitation in writing a STOP RUN
verb deeply embedded into his program :-)

Sometimes I have seen goto allergic people do this in Ada
too, interfacing the exit routine!




Sent via Deja.com http://www.deja.com/
Before you buy.




  parent reply	other threads:[~2000-04-21  0:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-04-19  0:00 checking a loop execution pumilia
2000-04-19  0:00 ` DuckE
2000-04-20  0:00 ` Geoff Bull
2000-04-20  0:00 ` tmoran
2000-04-20  0:00   ` Charles Hixson
2000-04-20  0:00 ` Andreas Schulz
2000-04-20  0:00 ` chad
2000-04-21  0:00   ` Robert Dewar
2000-04-21  0:00   ` Robert Dewar [this message]
2000-04-22  0:00     ` Chad R. Meiners
2000-04-23  0:00       ` Robert Dewar
2000-04-24  0:00         ` Ehud Lamm
2000-04-24  0:00           ` Ehud Lamm
2000-04-24  0:00       ` Bill Greene
replies disabled

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