comp.lang.ada
 help / color / mirror / Atom feed
* Re: How to implement a continue statement in Ada?
       [not found] <35EA8153.7BFC91E3@physics.purdue.edu>
@ 1998-08-31  0:00 ` Robert I. Eachus
  1998-08-31  0:00   ` Robert T. Sagris
  1998-08-31  0:00 ` Norman H. Cohen
  1998-09-01  0:00 ` alan walkington
  2 siblings, 1 reply; 27+ messages in thread
From: Robert I. Eachus @ 1998-08-31  0:00 UTC (permalink / raw)


In article <35EA8153.7BFC91E3@physics.purdue.edu> "Robert T. Sagris" <robs@physics.purdue.edu> writes:

 > I was wondering if there is a general way of implementing 
 > the behavior of C's continue statement in Ada.

   No, there are several techniques, but nothing which really covers
everything. 

 > If at all possible without using a goto statement.

   Well, that works in all cases, but certainly is not the best in all
cases. 

 > Basically what I am asking:

 >  Is there a way to skip the current iteration of a loop
 >  but continue with the normal progression of the loop.

 >  In C, I could write:

 >     i = 0;
 >     while (i < 10) {

 >	 if (a[i] == 0) {
 >	    i++;
 >	    continue;
 >	 }

 >	 a[i] = x / a[i];
 >	 i++;
 >     }

       Ouch!  Assuming that "i" really is an iteration counter;

      for I in 0 .. 9 loop
        if A(I) /= 0
        then A(I) := X / A(I);
        end if;
      end loop;

       Seems like the natural translation, but I'm not sure that
answers your question.
--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  1998-08-31  0:00 ` How to implement a continue statement in Ada? Robert I. Eachus
@ 1998-08-31  0:00   ` Robert T. Sagris
  1998-09-01  0:00     ` Matthew Heaney
  0 siblings, 1 reply; 27+ messages in thread
From: Robert T. Sagris @ 1998-08-31  0:00 UTC (permalink / raw)


Robert I. Eachus wrote:
> 
> In article <35EA8153.7BFC91E3@physics.purdue.edu> "Robert T. Sagris" <robs@physics.purdue.edu> writes:
> 
>  > I was wondering if there is a general way of implementing
>  > the behavior of C's continue statement in Ada.
> 
>    No, there are several techniques, but nothing which really covers
> everything.
> 
>  > If at all possible without using a goto statement.
> 
>    Well, that works in all cases, but certainly is not the best in all
> cases.
> 
>  > Basically what I am asking:
> 
>  >  Is there a way to skip the current iteration of a loop
>  >  but continue with the normal progression of the loop.
> 
>  >  In C, I could write:
> 
>  >     i = 0;
>  >     while (i < 10) {
> 
>  >       if (a[i] == 0) {
>  >          i++;
>  >          continue;
>  >       }
> 
>  >       a[i] = x / a[i];
>  >       i++;
>  >     }
> 
>        Ouch!  Assuming that "i" really is an iteration counter;
> 
>       for I in 0 .. 9 loop
>         if A(I) /= 0
>         then A(I) := X / A(I);
>         end if;
>       end loop;
> 
>        Seems like the natural translation, but I'm not sure that
> answers your question.
> --
> 
>                                         Robert I. Eachus
> 
> with Standard_Disclaimer;
> use  Standard_Disclaimer;
> function Message (Text: in Clever_Ideas) return Better_Ideas is...

It seems that people have mistaken my code example for the specific
instance were I needed a continue statement.

I only gave it so there was an example of a C use of the continue
statement. 
What I was asking; how would implement the code given, which realy is
just a general example, in Ada. Specifically so you could use it any any
loop were you needed to skip an iteration.

Thanks for the answers so far.

Robbi Sagris




^ permalink raw reply	[flat|nested] 27+ messages in thread

* How to implement a continue statement in Ada?
@ 1998-08-31  0:00 Robert T. Sagris
  1998-09-01  0:00 ` Dr Richard A. O'Keefe
  1998-09-01  0:00 ` dewarr
  0 siblings, 2 replies; 27+ messages in thread
From: Robert T. Sagris @ 1998-08-31  0:00 UTC (permalink / raw)


I was wondering if there is a general way of implementing 
the behavior of C's continue statement in Ada.

If at all possible without using a goto statement.

Basically what I am asking:

Is there a way to skip the current iteration of a loop
but continue with the normal progression of the loop.

In C, I could write:

   i = 0;
   while (i < 10) {

      if (a[i] == 0) {
         i++;
         continue;
      }

      a[i] = x / a[i];
      i++;
   }

Thanks for any information you can give me.

Robbi Sagris




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
       [not found] <35EA8153.7BFC91E3@physics.purdue.edu>
  1998-08-31  0:00 ` How to implement a continue statement in Ada? Robert I. Eachus
@ 1998-08-31  0:00 ` Norman H. Cohen
  1998-09-01  0:00 ` alan walkington
  2 siblings, 0 replies; 27+ messages in thread
From: Norman H. Cohen @ 1998-08-31  0:00 UTC (permalink / raw)



Robert T. Sagris wrote in message <35EA8153.7BFC91E3@physics.purdue.edu>...

>I was wondering if there is a general way of implementing
>the behavior of C's continue statement in Ada.
>
>If at all possible without using a goto statement.
>
>Basically what I am asking:
>
>Is there a way to skip the current iteration of a loop
>but continue with the normal progression of the loop.
>
>In C, I could write:
>
>   i = 0;
>   while (i < 10) {
>
>      if (a[i] == 0) {
>         i++;
>         continue;
>      }
>
>      a[i] = x / a[i];
>      i++;
>   }
>
>Thanks for any information you can give me.
>
>Robbi Sagris

First of all, I find that most uses of "continue" reflect confusion about
the control structure.  For example, the loop above can be transformed into
the MUCH clearer

   for (i=0; i < 10; i++) {
      if ( a[i] != 0 ) {
         a[i] = x/a[i];
      }
   }

Occasionally there is a legitimate use for something like "continue",  when
the decision to proceed to the next iteration is nested inside several
levels of conditional statements.  There are all sorts of tricks to achieve
this effect without using a "goto" -- a local block that both declares and
handles a local End_Of_Iteration exception so that "goto" can be spelled
"raise" instead, moving the contents of the loop body into a function so
that "goto" can be spelled "return" instead, surrounding the loop body with
an inner loop that will be executed for only one iteration so that "goto"
can be spelled "exit" instead -- but I find that the most straightforward,
most readily understood and easily maintained, and most efficient solution
in this situation is to spell "goto" as "goto".  That is, add the labeled
statement

   <<End_Of_Iteration>> null;

to the end of the loop to be continued, and write

   goto End_Of_Iteration;

where a C programmer would write "continue".

-- Norman Cohen






^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
       [not found] <35EA8153.7BFC91E3@physics.purdue.edu>
  1998-08-31  0:00 ` How to implement a continue statement in Ada? Robert I. Eachus
  1998-08-31  0:00 ` Norman H. Cohen
@ 1998-09-01  0:00 ` alan walkington
  1998-09-02  0:00   ` Dr Richard A. O'Keefe
  2 siblings, 1 reply; 27+ messages in thread
From: alan walkington @ 1998-09-01  0:00 UTC (permalink / raw)



Robert T. Sagris wrote in message <35EA8153.7BFC91E3@physics.purdue.edu>...
>I was wondering if there is a general way of implementing
>the behavior of C's continue statement in Ada.


As you have seen from the responses, the answer is NO.

however, using psuedocode (so don't tell me it won't compile--:-)) ..

in C:

  loop statement
     if (conditional on iterator)
        continue;
     end if;

     more code
  end loop

you must INVERT the logic in ada:

  loop statement
    if NOT (conditional on iterator)
       more code
    end if
  end loop

both these will skip 'more code' on the test of an iterator


Alan Walkington
Sr. Software Engineer
UDLP, San Jose
(remove the obvious from the e-mail address)
walkyANTISPAM@netmagic.net







^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  1998-09-01  0:00 ` Dr Richard A. O'Keefe
@ 1998-09-01  0:00   ` dewarr
  1998-09-03  0:00     ` Dr Richard A. O'Keefe
  0 siblings, 1 reply; 27+ messages in thread
From: dewarr @ 1998-09-01  0:00 UTC (permalink / raw)


In article <35EB7036.5585@atlas.otago.ac.nz>,
  ok@atlas.otago.ac.nz wrote:
> Robert T. Sagris wrote:
> > I was wondering if there is a general way of implementing
> > the behavior of C's continue statement in Ada.
> >
> > If at all possible without using a goto statement.
>
> Will you accept an 'exit'?
>
> Loop statements can have names (LRM 5.5).
> But so can blocks (LRM 5.6).
>
> The general C form
>
>    for (init; cond; updt) stmt
>
> can be converted to
>
>    begin
>       init;
>    Loop_All:
>       while cond loop
>    Loop_Body:
>          begin
>             stmt
>          end;
>          updt;
>       end loop
>    end;
>
> 'break'      => exit Loop_All;
> 'continue'   => exit Loop_Body;
>
> Obvious simplifications apply to particular cases.
>
This is wrong. It is also a good reminder to PLEASE compile what
you suggest before you suggest it. I always do (I do not trust
my knowledge of Ada to be 100% reliable, especially in the rush
of replying to newsgroup articles).

The exit statement can ONLY be used to exit from a loop in Ada,
it cannot be used to exit from a block in the manner suggested
above. If you had compiled your suggestion you would have got
an error message similar to

   k.adb:4:07: invalid loop name in exit statement

Note that this also serves as a reminder that you have to be
careful reading responses to CLA, do not assume that all posts
are technicaly correct.

It is possible to replace the block in Richard's example by a dummy
loop:

   Loop_Body : loop
      ...
      exit Loop_Body;
   end Loop_Body;

but you really have to be quite allergic to gotos to prefer this to
the simple and straightforward use of a goto to achieve a continue.

Note also that the syntax in Richard's example is quite wrong (again
something that compiling it would have revealed). If a loop or block
is named, the name MUST be repeated on the end

Robert Dewar

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  1998-08-31  0:00   ` Robert T. Sagris
@ 1998-09-01  0:00     ` Matthew Heaney
  0 siblings, 0 replies; 27+ messages in thread
From: Matthew Heaney @ 1998-09-01  0:00 UTC (permalink / raw)


"Robert T. Sagris" <robs@physics.purdue.edu> writes:

> What I was asking; how would implement the code given, which really is
> just a general example, in Ada. Specifically so you could use it any
> any loop were you needed to skip an iteration.

As has been pointed out, THE way to implement continue in Ada is to use
a goto:

for I in X .. Y loop
   <do some work>

   if P then
      goto Continue;
   end if;

   <do some more work>

   <<Continue>> null;
end loop;


As Robert pointed out, if you label the loop, then you can include the
loop label in the name of the target of the goto (this is a stylistic
convention):

Paint_House:
for I in X .. Y loop
   <do some work>

   if P then
      goto Continue_Paint_House;
   end if;

   <do some more work>

   <<Continue_Paint_House>> null;
end loop Paint_House;





^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  1998-08-31  0:00 Robert T. Sagris
  1998-09-01  0:00 ` Dr Richard A. O'Keefe
@ 1998-09-01  0:00 ` dewarr
  1 sibling, 0 replies; 27+ messages in thread
From: dewarr @ 1998-09-01  0:00 UTC (permalink / raw)


In article <35EA816A.E11FEA85@physics.purdue.edu>,
  "Robert T. Sagris" <robs@physics.purdue.edu> wrote:
> I was wondering if there is a general way of implementing
> the behavior of C's continue statement in Ada.
>
> If at all possible without using a goto statement.
>
> Basically what I am asking:
>
> Is there a way to skip the current iteration of a loop
> but continue with the normal progression of the loop.
>
> In C, I could write:
>
>    i = 0;
>    while (i < 10) {
>
>       if (a[i] == 0) {
>          i++;
>          continue;
>       }
>
>       a[i] = x / a[i];
>       i++;
>    }
>
> Thanks for any information you can give me.
>
> Robbi Sagris
>

The only general way of implementing a continue is to use a goto.
Use a stylized approach like

  This_Loop : loop
    ...
    if ... then
       goto Continue_This_Loop;
    end if;
    ...
    ...
  <<Continue_This_Loop>> null;
  end loop This_Loop;

This works fine, unless you have some inexplicable allergy to
typing G-O-T-O :-)

See the archives for a recent discussion of the use of gotos
for this purpose.

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  1998-08-31  0:00 Robert T. Sagris
@ 1998-09-01  0:00 ` Dr Richard A. O'Keefe
  1998-09-01  0:00   ` dewarr
  1998-09-01  0:00 ` dewarr
  1 sibling, 1 reply; 27+ messages in thread
From: Dr Richard A. O'Keefe @ 1998-09-01  0:00 UTC (permalink / raw)


Robert T. Sagris wrote:
> I was wondering if there is a general way of implementing
> the behavior of C's continue statement in Ada.
> 
> If at all possible without using a goto statement.

Will you accept an 'exit'?

Loop statements can have names (LRM 5.5).
But so can blocks (LRM 5.6).

The general C form

   for (init; cond; updt) stmt

can be converted to

   begin
      init;
   Loop_All:
      while cond loop
   Loop_Body:
         begin
            stmt
         end;
         updt;
      end loop
   end;

'break'      => exit Loop_All;
'continue'   => exit Loop_Body;

Obvious simplifications apply to particular cases.




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  1998-09-02  0:00   ` Dr Richard A. O'Keefe
@ 1998-09-02  0:00     ` alan walkington
  1998-09-02  0:00     ` Matthew Heaney
  1998-09-03  0:00     ` dewarr
  2 siblings, 0 replies; 27+ messages in thread
From: alan walkington @ 1998-09-02  0:00 UTC (permalink / raw)



Dr Richard A. O'Keefe wrote in message <35ECD5FD.5F53@atlas.otago.ac.nz>...
>alan walkington wrote:
>>
>> Robert T. Sagris wrote in message
<35EA8153.7BFC91E3@physics.purdue.edu>...
>> >I was wondering if there is a general way of implementing
>> >the behavior of C's continue statement in Ada.
>>
>> As you have seen from the responses, the answer is NO.
>
>Clearly I have missed some responses.

IMHO the original poster was looking for an atomic ada construct similar to
the 'continue' statement in C.  We, including myself, responded with
'work-arounds' that achieved the same thing.

>What exactly is wrong with
> - Robert Dewar's suggestion of using 'goto', or

Some of us who write Ada for the US government are stuck with coding
standards which prohibit the use of 'goto' under any circumstance.  Not good
CS, but we have to learn to live with it.

> - my suggestion of using a nested named block and named exits?

I don't know how to use the 'exit' statement to get out of a block.
Elucidate, dear doctor?

>Both suggestions "implement the behaviour", which is skipping the
>rest of the body of the loop.

Yes, that's also what my psuedo code does.

>Is it the fact that you have to invent names,
>which you do not in C?
>Is it the fact that these translations are _too_ powerful,
>handling multi-level exit, which the C version does not?

Please lets not get into a 'which language is better' mode.  I've been using
Ada for almost 15 years now, and C for longer.  Both Ada and C/C++ have
there uses.

Alan Walkington
Sr. Software Engineer
UDLP, San Jose
(remove the obvious from the e-mail address)
walkyANTISPAM@netmagic.net








^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  1998-09-01  0:00 ` alan walkington
@ 1998-09-02  0:00   ` Dr Richard A. O'Keefe
  1998-09-02  0:00     ` alan walkington
                       ` (2 more replies)
  0 siblings, 3 replies; 27+ messages in thread
From: Dr Richard A. O'Keefe @ 1998-09-02  0:00 UTC (permalink / raw)


alan walkington wrote:
> 
> Robert T. Sagris wrote in message <35EA8153.7BFC91E3@physics.purdue.edu>...
> >I was wondering if there is a general way of implementing
> >the behavior of C's continue statement in Ada.
> 
> As you have seen from the responses, the answer is NO.

Clearly I have missed some responses.
What exactly is wrong with
 - Robert Dewar's suggestion of using 'goto', or
 - my suggestion of using a nested named block and named exits?
Both suggestions "implement the behaviour", which is skipping the
rest of the body of the loop.
Is it the fact that you have to invent names,
which you do not in C?
Is it the fact that these translations are _too_ powerful,
handling multi-level exit, which the C version does not?




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  1998-09-02  0:00   ` Dr Richard A. O'Keefe
  1998-09-02  0:00     ` alan walkington
@ 1998-09-02  0:00     ` Matthew Heaney
  1998-09-03  0:00     ` dewarr
  2 siblings, 0 replies; 27+ messages in thread
From: Matthew Heaney @ 1998-09-02  0:00 UTC (permalink / raw)


"Dr Richard A. O'Keefe" <ok@atlas.otago.ac.nz> writes:

> What exactly is wrong with
>  - Robert Dewar's suggestion of using 'goto', or
>  - my suggestion of using a nested named block and named exits?

What do you mean by a "named block and named exit"?  Are you suggesting
using an exit to terminate a block?  That wouldn't be legal.






^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  1998-09-03  0:00     ` Dr Richard A. O'Keefe
@ 1998-09-03  0:00       ` dennison
  0 siblings, 0 replies; 27+ messages in thread
From: dennison @ 1998-09-03  0:00 UTC (permalink / raw)


In article <35EDD44B.63F2@atlas.otago.ac.nz>,
  ok@atlas.otago.ac.nz wrote:

> I _was_ using Ada a fair bit last year, and readers will realise
> from this that I had never actually _needed_ to emulate C's
> 'continue', or for that matter, multi-level loop exit.

I have used Ada for 9 years now, and have yet to tell myself, "gee, I really
wish I could do a continue". I think this is mostly an issue for C converts.

I' sure there are perfectly legitimate uses for it, but the two times I used
"continue" in C code, I probably shouldn't have.


--
T.E.D.

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  1998-09-01  0:00   ` dewarr
@ 1998-09-03  0:00     ` Dr Richard A. O'Keefe
  1998-09-03  0:00       ` dennison
  0 siblings, 1 reply; 27+ messages in thread
From: Dr Richard A. O'Keefe @ 1998-09-03  0:00 UTC (permalink / raw)


dewarr@my-dejanews.com wrote:
> Note also that the syntax in Richard's example is quite wrong (again
> something that compiling it would have revealed). If a loop or block
> is named, the name MUST be repeated on the end

I owe everyone an apology for that.
My only excuse is that there is no Ada compiler installed on either
of the machines I normally use (I do mean to fix that) so I wasn't
_able_ to test before posting.
(Yes, I do have the LRM on-line, but the HTML file names on the
disc are in upper case, and the references are in lower or mixed
case, which means none of the links work, so finding things was
a bit painful.  That one I _have_ fixed now.)

I _was_ using Ada a fair bit last year, and readers will realise
from this that I had never actually _needed_ to emulate C's
'continue', or for that matter, multi-level loop exit.




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  1998-09-02  0:00   ` Dr Richard A. O'Keefe
  1998-09-02  0:00     ` alan walkington
  1998-09-02  0:00     ` Matthew Heaney
@ 1998-09-03  0:00     ` dewarr
  2 siblings, 0 replies; 27+ messages in thread
From: dewarr @ 1998-09-03  0:00 UTC (permalink / raw)


In article <35ECD5FD.5F53@atlas.otago.ac.nz>,
  ok@atlas.otago.ac.nz wrote:
> alan walkington wrote:
> >
> > Robert T. Sagris wrote in message <35EA8153.7BFC91E3@physics.purdue.edu>...
> > >I was wondering if there is a general way of implementing
> > >the behavior of C's continue statement in Ada.
> >
> > As you have seen from the responses, the answer is NO.
>
> Clearly I have missed some responses.
> What exactly is wrong with
>  - Robert Dewar's suggestion of using 'goto', or
>  - my suggestion of using a nested named block and named exits?
> Both suggestions "implement the behaviour", which is skipping the
> rest of the body of the loop.
> Is it the fact that you have to invent names,
> which you do not in C?
> Is it the fact that these translations are _too_ powerful,
> handling multi-level exit, which the C version does not?
>

Quite a bit is wrong with "my suggestion of using a nested named
block and named exit", namely neither Ada 95 nor Ada 83 permit
exiting from a named block!

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
@ 2000-02-08  0:00 Oliver Kellogg
  2000-02-08  0:00 ` Ted Dennison
  2000-02-08  0:00 ` David Starner
  0 siblings, 2 replies; 27+ messages in thread
From: Oliver Kellogg @ 2000-02-08  0:00 UTC (permalink / raw)


In article <6smb7v$j39$1@nnrp1.dejanews.com>,
  dennison@telepath.com wrote:

> I have used Ada for 9 years now, and have yet to tell myself,
> "gee, I really wish I could do a continue". I think this is
> mostly an issue for C converts.

I care to disagree.

We have a coding rule that forbids the use of goto.
I generally like that rule - it prevents insufficiently
trained people from messing around.

Then again, I have never needed goto for other than
emulating "continue". So I see this as an exceptional case.

I hereby cast my vote for introducing the "continue"
keyword in Ada-0x

Oliver M. Kellogg


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




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  2000-02-08  0:00 How to implement a continue statement in Ada? Oliver Kellogg
  2000-02-08  0:00 ` Ted Dennison
@ 2000-02-08  0:00 ` David Starner
  2000-02-08  0:00   ` Aidan Skinner
  1 sibling, 1 reply; 27+ messages in thread
From: David Starner @ 2000-02-08  0:00 UTC (permalink / raw)


On Tue, 08 Feb 2000 16:36:20 GMT, Oliver Kellogg <okellogg@my-deja.com> wrote:
>In article <6smb7v$j39$1@nnrp1.dejanews.com>,
>  dennison@telepath.com wrote:
>
>> I have used Ada for 9 years now, and have yet to tell myself,
>> "gee, I really wish I could do a continue". I think this is
>> mostly an issue for C converts.
>
>I care to disagree.
>
>We have a coding rule that forbids the use of goto.
>I generally like that rule - it prevents insufficiently
>trained people from messing around.
>
>Then again, I have never needed goto for other than
>emulating "continue". So I see this as an exceptional case.

I disagree with that rule. The goto statement is the most
powerful control structure, and judiciously used, is 
very useful. My most recent use of a goto was to emulate
tail recursion. Does that mean that Ada needs a tail
recursion call? 

-- 
David Starner - dstarner98@aasaa.ofe.org
Only a nerd would worry about wrong parentheses with
square brackets. But that's what mathematicians are.
   -- Dr. Burchard, math professor at OSU




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  2000-02-08  0:00 How to implement a continue statement in Ada? Oliver Kellogg
@ 2000-02-08  0:00 ` Ted Dennison
  2000-02-09  0:00   ` Roger Barnett
  2000-02-08  0:00 ` David Starner
  1 sibling, 1 reply; 27+ messages in thread
From: Ted Dennison @ 2000-02-08  0:00 UTC (permalink / raw)


In article <87pgm3$o3p$1@nnrp1.deja.com>,
  Oliver Kellogg <okellogg@my-deja.com> wrote:
> In article <6smb7v$j39$1@nnrp1.dejanews.com>,
>   dennison@telepath.com wrote:
>
> > I have used Ada for 9 years now, and have yet to tell myself,
> > "gee, I really wish I could do a continue". I think this is
> > mostly an issue for C converts.
>
> Then again, I have never needed goto for other than
> emulating "continue". So I see this as an exceptional case.
>
> I hereby cast my vote for introducing the "continue"
> keyword in Ada-0x

Hmmm. That quote sounded like me, but I don't exactly share that
sentiment. A quick deja search shows that I posted that back on
September 3, 1998. I realize that at the time no one called me on the
statement, but I think the statue of limitations on arguing the point
with me has long since passed. :-)

For a post of mine on the subject of slightly more recent vintage, try
the following, posted less than a month ago under the thread title of
"Re: bitwise comparators":

> C's continue statement would be helpful often in my Ada code,
> but it does make the code tougher to follow.

As you can see, my opinion has changed slightly over the intervening 1.4
years. Apparently I've written a lot of loops since then. :-)

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


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




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  2000-02-08  0:00 ` David Starner
@ 2000-02-08  0:00   ` Aidan Skinner
  2000-02-09  0:00     ` Ted Dennison
  2000-02-09  0:00     ` David Starner
  0 siblings, 2 replies; 27+ messages in thread
From: Aidan Skinner @ 2000-02-08  0:00 UTC (permalink / raw)


dvdeug@x8b4e53cd.dhcp.okstate.edu (David Starner) writes:

> I disagree with that rule. The goto statement is the most
> powerful control structure, and judiciously used, is 
> very useful. My most recent use of a goto was to emulate
> tail recursion. Does that mean that Ada needs a tail

I would expect this case to be picked up by the compiler, without the
need for an explicit goto. Was there a reason why the appropriate
section of code couldn't be put into a (possibly nested) procedure and 
recurse itself?

- Aidan
-- 
http://www.skinner.demon.co.uk/aidan/
Before asking a tech a question, think: "Does this person care? Is
this in anyway meaningful to their existence?". If the answer is "No", 
please read the documentation supplied, specifically Chapter 9: Suicide.




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  2000-02-08  0:00 ` Ted Dennison
@ 2000-02-09  0:00   ` Roger Barnett
  0 siblings, 0 replies; 27+ messages in thread
From: Roger Barnett @ 2000-02-09  0:00 UTC (permalink / raw)


In article: <87q53f$6q6$1@nnrp1.deja.com>  Ted Dennison <dennison@telepath.com> 
writes:
> 
> For a post of mine on the subject of slightly more recent vintage, try
> the following, posted less than a month ago under the thread title of
> "Re: bitwise comparators":
> 
> > C's continue statement would be helpful often in my Ada code,
> > but it does make the code tougher to follow.


I've always thought that the C continue statement provides all the
problems of 'goto' but without the clarity  ('break' is almost as bad).

Perhaps if an Ada equivalent required the use of a labelled loop
construct to make it explicit what was being continued ?

-- 
Roger Barnett







^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  2000-02-08  0:00   ` Aidan Skinner
@ 2000-02-09  0:00     ` Ted Dennison
  2000-02-12  0:00       ` Jeff Carter
  2000-02-14  0:00       ` Oliver Kellogg
  2000-02-09  0:00     ` David Starner
  1 sibling, 2 replies; 27+ messages in thread
From: Ted Dennison @ 2000-02-09  0:00 UTC (permalink / raw)


In article <m3ya8v1g93.fsf@skinner.demon.co.uk>,
  Aidan Skinner <aidan@skinner.demon.co.uk> wrote:
> I would expect this case to be picked up by the compiler, without the
> need for an explicit goto. Was there a reason why the appropriate
> section of code couldn't be put into a (possibly nested) procedure and
> recurse itself?

That does raise a good issue. Often when this comes up I will fudge it
by putting the code in the loop inside of a subroutine, from which I can
simulate continue with a "return". This could also be done with an
"exit" statement by putting the code in another loop that has an "exit;"
at the end. But that looks silly, while the subroutine often makes some
sense in and of itself.

Given that such workarounds (hacks) exist, why not put continue
capability in Ada 0X by allowing the "exit" statement to exit outside of
a begin..end block? The fact that you can't do this is actually a common
confusion for newbies anyway.

I'll admit its a bit "heavy" of a solution, since it involves another
level of nesting. But it has some advantages to offset that. The
existence of the block would tip readers off that a early termination
may exist. Also, this is more powerful that a meer "continue", because
you can explicitly specify the scope of the statements that get skipped.
For instance, you could have some extra code outside of the block at the
end of the loop that does not get skipped.

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


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




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  2000-02-08  0:00   ` Aidan Skinner
  2000-02-09  0:00     ` Ted Dennison
@ 2000-02-09  0:00     ` David Starner
  2000-02-10  0:00       ` Aidan Skinner
  2000-02-12  0:00       ` Character vs. String comparisons (was: Re: How to implement a continue statement in Ada?) Jeff Carter
  1 sibling, 2 replies; 27+ messages in thread
From: David Starner @ 2000-02-09  0:00 UTC (permalink / raw)


On 08 Feb 2000 22:28:08 +0000, Aidan Skinner <aidan@skinner.demon.co.uk> wrote:
>dvdeug@x8b4e53cd.dhcp.okstate.edu (David Starner) writes:
>
>> I disagree with that rule. The goto statement is the most
>> powerful control structure, and judiciously used, is 
>> very useful. My most recent use of a goto was to emulate
>> tail recursion. Does that mean that Ada needs a tail
>
>I would expect this case to be picked up by the compiler, without the
>need for an explicit goto. Was there a reason why the appropriate
>section of code couldn't be put into a (possibly nested) procedure and 
>recurse itself?

The code was part of a lexer, and looked like

function lexer return token is begin
<<label>>
-- Bookkeeping
if char(1) = '*' then
-- Deal with it
elsif char(1) = ''' then
...
elsif char (1) = '(' and char (2) = '*' then
   -- Eat the comment
   either goto label or return lexer;
elsif char (1) =  '%' then
...

GNAT didn't recognize it as tail recursion, so the non-recursive
version performed better with certain (pathological) code. I'd
be surprised to find that any Ada compiler did much better on
tail recursion than GNAT, as it's not important for most Ada
programs.

-- 
David Starner - dstarner98@aasaa.ofe.org
Only a nerd would worry about wrong parentheses with
square brackets. But that's what mathematicians are.
   -- Dr. Burchard, math professor at OSU




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  2000-02-09  0:00     ` David Starner
@ 2000-02-10  0:00       ` Aidan Skinner
  2000-02-12  0:00       ` Character vs. String comparisons (was: Re: How to implement a continue statement in Ada?) Jeff Carter
  1 sibling, 0 replies; 27+ messages in thread
From: Aidan Skinner @ 2000-02-10  0:00 UTC (permalink / raw)


dvdeug@x8b4e53cd.dhcp.okstate.edu (David Starner) writes:

> On 08 Feb 2000 22:28:08 +0000, Aidan Skinner <aidan@skinner.demon.co.uk> wrote:

> >I would expect this case to be picked up by the compiler, without the
> >need for an explicit goto. Was there a reason why the appropriate

> GNAT didn't recognize it as tail recursion, so the non-recursive
> version performed better with certain (pathological) code. I'd

Having just tried a simple example, it doesn't recognise this at
all. I'm a bit surprised by this TBH...

> tail recursion than GNAT, as it's not important for most Ada
> programs.

I don't know, I use it quite a lot in libra, mostly in the data
structures (a lot of the code which walks through the strucutres uses
tail recursion).

It's probably over-used though, so I may change it...

- Aidan
-- 
http://www.skinner.demon.co.uk/aidan/
Before asking a tech a question, think: "Does this person care? Is
this in anyway meaningful to their existence?". If the answer is "No", 
please read the documentation supplied, specifically Chapter 9: Suicide.




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Character vs. String comparisons (was: Re: How to implement a continue  statement in Ada?)
  2000-02-09  0:00     ` David Starner
  2000-02-10  0:00       ` Aidan Skinner
@ 2000-02-12  0:00       ` Jeff Carter
  2000-02-12  0:00         ` David Starner
  1 sibling, 1 reply; 27+ messages in thread
From: Jeff Carter @ 2000-02-12  0:00 UTC (permalink / raw)


David Starner wrote:
> elsif char (1) = '(' and char (2) = '*' then

Is there some reason you didn't write

elsif char (1 .. 2) = "(*";

? Just curious.

-- 
Jeff Carter
"You empty-headed animal-food-trough wiper."
Monty Python & the Holy Grail




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  2000-02-09  0:00     ` Ted Dennison
@ 2000-02-12  0:00       ` Jeff Carter
  2000-02-14  0:00       ` Oliver Kellogg
  1 sibling, 0 replies; 27+ messages in thread
From: Jeff Carter @ 2000-02-12  0:00 UTC (permalink / raw)


Ted Dennison wrote:
> Given that such workarounds (hacks) exist, why not put continue
> capability in Ada 0X by allowing the "exit" statement to exit outside of
> a begin..end block? The fact that you can't do this is actually a common
> confusion for newbies anyway.

Of course, there is a horrible way to do this already:

loop
   declare
      Continue : exception;
   begin
      ...
      raise Continue; -- Also known as the continue statement
      ...
   exception
   when Continue =>
      null;
   end;
end loop;

-- 
Jeff Carter
"You empty-headed animal-food-trough wiper."
Monty Python & the Holy Grail




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Character vs. String comparisons (was: Re: How to implement a continue  statement in Ada?)
  2000-02-12  0:00       ` Character vs. String comparisons (was: Re: How to implement a continue statement in Ada?) Jeff Carter
@ 2000-02-12  0:00         ` David Starner
  0 siblings, 0 replies; 27+ messages in thread
From: David Starner @ 2000-02-12  0:00 UTC (permalink / raw)


On Sat, 12 Feb 2000 21:50:33 GMT, Jeff Carter <jrcarter010@earthlink.net> wrote:
>David Starner wrote:
>> elsif char (1) = '(' and char (2) = '*' then
>
>Is there some reason you didn't write
>
>elsif char (1 .. 2) = "(*";

Yes. It actually looked like 
   elsif char (I + 1) = '(' and then char (I + 2) = '*' then ...
The way the buffer was set up, the trailing character would always be
a space. As long as anything didn't read past a space, I don't have
to take the extra code to check that I < EOL. char (I+1 .. I + 3) = 'for'
could potentially overflow the buffer, whereas char(I+1) = 'f' and then
char (I+2) = 'o' and then char (I + 3) = 'r' won't. Also, it looked like
elsif char (I+1) = '(' then
   if char (I+2) = '*' then
      -- Do comment things
   else
      -- Do open parenthesis things
   end if;
...
-- 
David Starner - dstarner98@aasaa.ofe.org
Only a nerd would worry about wrong parentheses with
square brackets. But that's what mathematicians are.
   -- Dr. Burchard, math professor at OSU




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: How to implement a continue statement in Ada?
  2000-02-09  0:00     ` Ted Dennison
  2000-02-12  0:00       ` Jeff Carter
@ 2000-02-14  0:00       ` Oliver Kellogg
  1 sibling, 0 replies; 27+ messages in thread
From: Oliver Kellogg @ 2000-02-14  0:00 UTC (permalink / raw)


In article <87s92d$lj1$1@nnrp1.deja.com>,
  Ted Dennison <dennison@telepath.com> wrote:

> Given that such workarounds (hacks) exist, why not put continue
> capability in Ada 0X by allowing the "exit" statement to exit
> outside of a begin..end block? The fact that you can't do this
> is actually a common confusion for newbies anyway.

A agree wholeheartedly. This should apply to both the
exit and the continue statement.

However, I still think adding a "continue" statement
to Ada is a good idea.

"continue" is complementary to "exit" in nature
and the same syntax rules should apply to both.
E.g. the continue statement could take an optional
loop_designator (just like exit) to make possible
continuing to outer loops in the case of nested loops.

Oliver M. Kellogg
-- okellogg at freenet dot de



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




^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2000-02-14  0:00 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-08  0:00 How to implement a continue statement in Ada? Oliver Kellogg
2000-02-08  0:00 ` Ted Dennison
2000-02-09  0:00   ` Roger Barnett
2000-02-08  0:00 ` David Starner
2000-02-08  0:00   ` Aidan Skinner
2000-02-09  0:00     ` Ted Dennison
2000-02-12  0:00       ` Jeff Carter
2000-02-14  0:00       ` Oliver Kellogg
2000-02-09  0:00     ` David Starner
2000-02-10  0:00       ` Aidan Skinner
2000-02-12  0:00       ` Character vs. String comparisons (was: Re: How to implement a continue statement in Ada?) Jeff Carter
2000-02-12  0:00         ` David Starner
     [not found] <35EA8153.7BFC91E3@physics.purdue.edu>
1998-08-31  0:00 ` How to implement a continue statement in Ada? Robert I. Eachus
1998-08-31  0:00   ` Robert T. Sagris
1998-09-01  0:00     ` Matthew Heaney
1998-08-31  0:00 ` Norman H. Cohen
1998-09-01  0:00 ` alan walkington
1998-09-02  0:00   ` Dr Richard A. O'Keefe
1998-09-02  0:00     ` alan walkington
1998-09-02  0:00     ` Matthew Heaney
1998-09-03  0:00     ` dewarr
  -- strict thread matches above, loose matches on Subject: below --
1998-08-31  0:00 Robert T. Sagris
1998-09-01  0:00 ` Dr Richard A. O'Keefe
1998-09-01  0:00   ` dewarr
1998-09-03  0:00     ` Dr Richard A. O'Keefe
1998-09-03  0:00       ` dennison
1998-09-01  0:00 ` dewarr

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