comp.lang.ada
 help / color / mirror / Atom feed
From: dewarr@my-dejanews.com
Subject: Re: How to implement a continue statement in Ada?
Date: 1998/09/01
Date: 1998-09-01T00:00:00+00:00	[thread overview]
Message-ID: <6sgmk2$6n5$1@nnrp1.dejanews.com> (raw)
In-Reply-To: 35EB7036.5585@atlas.otago.ac.nz

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




  reply	other threads:[~1998-09-01  0:00 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-08-31  0:00 How to implement a continue statement in Ada? Robert T. Sagris
1998-09-01  0:00 ` Dr Richard A. O'Keefe
1998-09-01  0:00   ` dewarr [this message]
1998-09-03  0:00     ` Dr Richard A. O'Keefe
1998-09-03  0:00       ` dennison
1998-09-01  0:00 ` dewarr
     [not found] <35EA8153.7BFC91E3@physics.purdue.edu>
1998-08-31  0:00 ` 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     ` Matthew Heaney
1998-09-02  0:00     ` alan walkington
1998-09-03  0:00     ` dewarr
  -- strict thread matches above, loose matches on Subject: below --
2000-02-08  0:00 Oliver Kellogg
2000-02-08  0:00 ` David Starner
2000-02-08  0:00   ` Aidan Skinner
2000-02-09  0:00     ` David Starner
2000-02-10  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-08  0:00 ` Ted Dennison
2000-02-09  0:00   ` Roger Barnett
replies disabled

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