comp.lang.ada
 help / color / mirror / Atom feed
* Easy ADA question from a hapless Newbie
@ 1994-10-25 19:11 AJ JONES
  1994-10-25 21:07 ` Ken Anderson
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: AJ JONES @ 1994-10-25 19:11 UTC (permalink / raw)



Can anyone help me ? Im new to ADA, used to PASCAL.  Is there a way of ending a loop
such as a while loop, etc, by jumping to the end of that loop.  There used to be a
command in Pascal that would let you do this. I think it was something like stop. I
know that halt stopped the entire program.

Thanks

Adam





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

* Re: Easy ADA question from a hapless Newbie
  1994-10-25 19:11 Easy ADA question from a hapless Newbie AJ JONES
@ 1994-10-25 21:07 ` Ken Anderson
  1994-10-25 22:17 ` mcriley on BIX
  1994-10-26  3:09 ` Jimmy Fang
  2 siblings, 0 replies; 4+ messages in thread
From: Ken Anderson @ 1994-10-25 21:07 UTC (permalink / raw)


In comp.lang.ada you write:

Hi Adam,

>Can anyone help me?

I'll give it a shot.

> Is there a way of ending a loop such as a while loop, etc, by jumping to the
> end of that loop.  There used to be a command in Pascal that would let you
> do this. I think it was something like stop. I know that halt stopped the
> entire program.

You are looking for the exit statement.

declare
   A : INTEGER := 1;
begin
  loop
     exit when A > 5;
     A := A + 1;
  end loop;
end;

This code will increment A until it is greater than 5 at which time
it will exit the loop.

Note, the when clause is optional. You could also right.

declare
   A : INTEGER := 1;
begin
  loop
     exit;
     A := A + 1;
  end loop;
end;

In which case A would never be incremented, although it doesn't make
sense in this code, there are situations where the exit statement
without a when clause is useful.

Hope this helps,

Ken

P.S.

>I'm new to ADA, used to PASCAL.

Just a quick comment, its Ada not ADA. ADA is an acronym like the
American Dental Association.

P.P.S.

One additional comment, not a criticism, but when sending text to a USENET
newsgroup be sure to type a return every 80 or so characters. This helps
those of us who have to read news on a VT100 terminal. :)
--
--------------------------------------------------------------------------------
-Ken Anderson            Ken_Anderson@acm.org                       U.C. Irvine-
- "A knowledge of C is probably better than nothing." -- J.G.P. Barnes         -
-                 Finger kanderso@ics.uci.edu for PGP Public Key               -
--------------------------------------------------------------------------------



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

* Re: Easy ADA question from a hapless Newbie
  1994-10-25 19:11 Easy ADA question from a hapless Newbie AJ JONES
  1994-10-25 21:07 ` Ken Anderson
@ 1994-10-25 22:17 ` mcriley on BIX
  1994-10-26  3:09 ` Jimmy Fang
  2 siblings, 0 replies; 4+ messages in thread
From: mcriley on BIX @ 1994-10-25 22:17 UTC (permalink / raw)


A.J.Jones@bradford.ac.uk (AJ JONES) writes:


>Can anyone help me ? Im new to ADA, used to PASCAL.  Is there a way of ending a loop
>such as a while loop, etc, by jumping to the end of that loop.  There used to be a
>command in Pascal that would let you do this. I think it was something like stop. I
>know that halt stopped the entire program.

>Thanks

>Adam


Do you want to "jump to the end of that loop" so as to exit?
If so, use the "exit" statement, perhaps with the "when" modifier.

Do you want to skip over all the statements after a given condition
occurs and cycle back to the top of the loop?
If so, use an "if" statement and place all the conditionally executed
statements within it.

Marc A. Criley



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

* Re: Easy ADA question from a hapless Newbie
  1994-10-25 19:11 Easy ADA question from a hapless Newbie AJ JONES
  1994-10-25 21:07 ` Ken Anderson
  1994-10-25 22:17 ` mcriley on BIX
@ 1994-10-26  3:09 ` Jimmy Fang
  2 siblings, 0 replies; 4+ messages in thread
From: Jimmy Fang @ 1994-10-26  3:09 UTC (permalink / raw)


AJ JONES (A.J.Jones@bradford.ac.uk) wrote:

: Can anyone help me ? Im new to ADA, used to PASCAL.  Is there a way of
: ending a loop such as a while loop, etc, by jumping to the end of that
: loop.  There used to be a command in Pascal that would let you do this.
: I think it was something like stop. I know that halt stopped the entire
: program.

Try the "exit" statement.

loop
  sequence of statements 1;
     exit when <boolean condition>
  sequence of statements 2;
end loop;

The exit statment will cause the program execution to continue
at the next statement outside of the loop.  The second block of
statements will not be executed once the boolean condition is
met.


- Jim
---------------------------------------------------------------------
Undergradual Student	Swinburne University of Technology 
			Melbourne, Australia




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

end of thread, other threads:[~1994-10-26  3:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-10-25 19:11 Easy ADA question from a hapless Newbie AJ JONES
1994-10-25 21:07 ` Ken Anderson
1994-10-25 22:17 ` mcriley on BIX
1994-10-26  3:09 ` Jimmy Fang

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