* help with Ada question
@ 1992-10-27 15:47 pa.dec.com!nntpd2.cxo.dec.com!shodha!wallace
0 siblings, 0 replies; 4+ messages in thread
From: pa.dec.com!nntpd2.cxo.dec.com!shodha!wallace @ 1992-10-27 15:47 UTC (permalink / raw)
wallace@shodha (Richard Wallace) writes:
: wallace@shodha (Richard Wallace) writes:
: : rwalker@barnacle.micro.umn.edu (robert walker) writes:
: : :
: : : If neither an exit nor a goto statement were available for Ada, how
: : : might you simulate the action of an exit statement?
: : :
: :
: : The following is one of may ways to control loop itteration without the
: : exit and goto verbs. Note that I've only shown monotonicly increasing
: : loop control.
: :
: : You would have to introduce a guard action on the loop control statement an
d
: : use an if to control skipping statements thus:
: :
:
: It seems I wiped-out the other half of my emacs buffer! Sorry! I'll
: reconstruct the code fragment again.
:
: code fragment:
:
It seems my mailer is having problems... I saved this file out and what got
posted is truncated. Hmm... I'll try ONE more time.
LOOP_COUNTER := 1;
LOOP_EXIT := false;
MAIN_LOOP:
while ( not( LOOP_EXIT) and ( LOOP_COUNTER <= LOOP_MAXIMUM ) ) then
{do statements}
if {boolean clause} then
LOOP_EXIT := true; -- setup for a psudeo exit
end if;
if not( LOOP_EXIT ) then -- psuedo exit statment in this guard.
{do statements if guard is true, i.e. no exit statement}
end if;
LOOP_COUNTER := LOOP_COUNTER + 1;
end loop MAIN_LOOP;
This is one of many solutions. I hope this helps. Note that this is a
monotonically incrementing loop. To do the reverse clause you'd have to
count down. To change the increment you'd have to change the constant 1
in the LOOP_COUNTER assignment.
Aloha,
Richard
--------------
Richard Wallace
Senior Software Engineer
Digital Equipment Corporation
301 Rockrimmon Blvd. South
CXO2-1/7A
Colorado Springs, CO 80919-2398
(719)548-2792
<wallace@cookie.enet.dec.com>
"The opinions expresses are my own, B.P. may not *quite* agree..."
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: help with Ada question
@ 1992-11-04 3:11 portal!cup.portal.com!R_Tim_Coslet
0 siblings, 0 replies; 4+ messages in thread
From: portal!cup.portal.com!R_Tim_Coslet @ 1992-11-04 3:11 UTC (permalink / raw)
In article: <1992Nov1.090527.29814@beaver.cs.washington.edu>
pschwrtz@lynx.cs.washington.edu (Paul Schwartz) wrote:
>robert walker (rwalker@barnacle.micro.umn.edu) wrote:
>:
>: If neither an exit nor a goto statement were available for Ada, how
>: might you simulate the action of an exit statement?
>:
> The easiest way would be to put the loop in a block and use an
>EXCEPTION to get out of the loop. As in;
>fooLoop:
>BEGIN
> LOOP
> IF <condition> THEN
> RAISE Some_Error;
> END IF;
>
> stuff
> END LOOP;
> EXCEPTION
> WHEN Some_Error => NULL; --you just wanted out of the loop
>END fooLoop;
>
It may be EASY, but don't EVER use exceptions as a "normal" means of
exiting a loop!!!! The overhead of an exception may be significant and
this is a misuse of the feature!!!
This is fine, IFF the exit from the loop was because of an error condition
that would normally never occur.
Of course this is purely a "class assignment" question, as any real programming
rules would never prohibit use of exit statements!
R. Tim Coslet
Usenet: R_Tim_Coslet@cup.portal.com
technology, n. domesticated natural phenomena
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: help with Ada question
@ 1992-11-01 9:05 Paul Schwartz
0 siblings, 0 replies; 4+ messages in thread
From: Paul Schwartz @ 1992-11-01 9:05 UTC (permalink / raw)
robert walker (rwalker@barnacle.micro.umn.edu) wrote:
:
: I could use some help on an Ada question. I have a homework problem
: which states:
:
:
: If neither an exit nor a goto statement were available for Ada, how
: might you simulate the action of an exit statement?
:
:
: This is for a course in higher level languages. We are studying control
: structures of several languages. I have never programmed
: in Ada, and am new to the language.
:
: Thanks for any help in advance.
:
: Robert Walker
: rwalker@mermaid.micro.umn.edu
:
:
The easiest way would be to put the loop in a block and use an
EXCEPTION to get out of the loop. As in;
fooLoop:
BEGIN
LOOP
IF <condition> THEN
RAISE Some_Error;
END IF;
stuff
END LOOP;
EXCEPTION
WHEN Some_Error => NULL; --you just wanted out of the loop
END fooLoop;
--
>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<
Paul Schwartz pschwrtz@lynx.cs.washington.edu
^ permalink raw reply [flat|nested] 4+ messages in thread
* help with Ada question
@ 1992-10-27 15:31 pa.dec.com!nntpd2.cxo.dec.com!shodha!wallace
0 siblings, 0 replies; 4+ messages in thread
From: pa.dec.com!nntpd2.cxo.dec.com!shodha!wallace @ 1992-10-27 15:31 UTC (permalink / raw)
wallace@shodha (Richard Wallace) writes:
: rwalker@barnacle.micro.umn.edu (robert walker) writes:
: :
: : If neither an exit nor a goto statement were available for Ada, how
: : might you simulate the action of an exit statement?
: :
:
: The following is one of may ways to control loop itteration without the
: exit and goto verbs. Note that I've only shown monotonicly increasing
: loop control.
:
: You would have to introduce a guard action on the loop control statement and
: use an if to control skipping statements thus:
:
It seems I wiped-out the other half of my emacs buffer! Sorry! I'll
reconstruct the code fragment again.
code fragment:
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1992-11-04 3:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1992-10-27 15:47 help with Ada question pa.dec.com!nntpd2.cxo.dec.com!shodha!wallace
-- strict thread matches above, loose matches on Subject: below --
1992-11-04 3:11 portal!cup.portal.com!R_Tim_Coslet
1992-11-01 9:05 Paul Schwartz
1992-10-27 15:31 pa.dec.com!nntpd2.cxo.dec.com!shodha!wallace
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox