comp.lang.ada
 help / color / mirror / Atom feed
From: Ted Dennison<dennison@telepath.com>
Subject: Re: an infinate loop
Date: Fri, 13 Jul 2001 13:57:35 GMT
Date: 2001-07-13T13:57:35+00:00	[thread overview]
Message-ID: <j7D37.18227$Kf3.236286@www.newsranger.com> (raw)
In-Reply-To: tks6i2llqcla15@corp.supernews.com

In article <tks6i2llqcla15@corp.supernews.com>, Beau says...
>
>Hey I am in an infinate loop and don't understand why. here is my problem to

Look for a big red sign that says "EXIT".

Oh, you mean your *code*? :-)

For one thing, you have 4 nested loops in one big honking routine. For some
people that may be no big deal, but to me its unspeakably ugly. Consider at
least putting the 2 inner loops in their own routine.

For another, it is generally considered very bad form to use an unnamed exit
statement inside of a nested loop. Its too easy for the reader to loose track of
which loop is being broken out of, particularly on a largish set of loops like
you have here. 

For another, most of your "exit" statements are all at the tops of the loops. In
those cases you should probably reverse the test logic and use "while" loops
instead. 

For another, the innermost loop seems to have no code to handle the end of the
file:

>--another nested post-test loop to catch the end of a word. The end of
>--a word can be found by looking for blank spaces
>       LOOP
>     CASE Letter IS --if the character variable was a actual letter
>        --then add one to wordlength
>
>        WHEN 'a'..'z' |'A'..'Z' =>
>           WordLength := WordLength + 1;
>        WHEN OTHERS =>
>           NULL;
>          END CASE;
>
>     Get(File => Infile, Item => Letter);
>
>     EXIT WHEN Letter = ' ' OR ELSE Letter = '.'
>           OR ELSE Letter = '?' OR ELSE Letter = '!';
>
>  END LOOP;


Lastly, and most importantly, you are going through *way* too much work for this
task. You could be doing this entire job with one loop. It looks like you are
trying to somehow code a state machine using each loop to reperesent a state.
Loops are a pretty poor mechanism for representing state machine states. Instead
you should just encode the state in some variable, and do an "if" or "case" on
it inside your main character processing loop. Actually, the variable that keeps
track of which character in the word you are on could probably be made to do the
job. The other way to do state machines is to use "goto" for the state
transitions, but this looks like a school assignment, and I doubt your
instructor wants to see that (although some might like it).

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



  parent reply	other threads:[~2001-07-13 13:57 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-12 21:43 an infinate loop Beau
2001-07-13  3:21 ` DuckE
2001-07-13 13:57 ` Ted Dennison [this message]
2001-07-13 17:01   ` Jeffrey Carter
2001-07-13 18:11     ` Ted Dennison
2001-07-13 22:26       ` Jeffrey Carter
2001-07-16 15:14         ` Marin David Condic
2001-07-17 17:02           ` Matthias Kretschmer
2001-07-17 17:56             ` Marin David Condic
2001-07-17 19:25               ` Ted Dennison
2001-07-19 11:38                 ` Matthias Kretschmer
2001-07-19 14:28                   ` Ted Dennison
2001-07-17 17:13           ` Warren W. Gay VE3WWG
2001-07-14 23:41       ` Darren New
2001-07-16 13:24         ` Ted Dennison
2001-07-16 15:19           ` Marin David Condic
2001-07-13 20:40     ` chris.danx
2001-07-13 22:29       ` Jeffrey Carter
2001-07-14 14:00         ` Robert Dewar
2001-07-14 16:17           ` Negative Logic (was: Re: an infinate loop) Jeffrey Carter
2001-07-17  4:06             ` Robert Dewar
2001-07-17  4:23             ` Robert Dewar
2001-07-16  9:26           ` an infinate loop Philip Anderson
2001-07-19  9:32             ` an infinite [was: infinate] loop AG
2001-07-15 21:18   ` an infinate loop Matthias Kretschmer
2001-07-16 21:59   ` Stephen Leake
2001-07-13 16:48 ` C. Bauman
replies disabled

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