From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_00,TO_NO_BRKTS_FROM_MSSP autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,cf677878aa77e0d8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-07-13 06:57:40 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!feed.textport.net!newsranger.com!www.newsranger.com!not-for-mail Newsgroups: comp.lang.ada From: Ted Dennison References: Subject: Re: an infinate loop Message-ID: X-Abuse-Info: When contacting newsranger.com regarding abuse please X-Abuse-Info: forward the entire news article including headers or X-Abuse-Info: else we will not be able to process your request X-Complaints-To: abuse@newsranger.com NNTP-Posting-Date: Fri, 13 Jul 2001 09:57:35 EDT Organization: http://www.newsranger.com Date: Fri, 13 Jul 2001 13:57:35 GMT Xref: archiver1.google.com comp.lang.ada:9910 Date: 2001-07-13T13:57:35+00:00 List-Id: In article , 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