🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pascal.borland
Article #648

Re: WHAT COULD BE WRONG?

#648
From: Frank Peelo
Date: Thu, 18 May 2000 00:00
55 lines
2563 bytes
<br-pede@online.no> wrote in message
news:D0OU4.6707$C9.118410@news1.online.no...
>
>
> I am trying to make a software, where the user can put in some word, and
the
> program will look and see if the word(s) is in a wordlist file. Everything
> is working pretty well, except this: The procedure is running in a
recursive
> way, that if you want to look up more than one word, you only put it in
next
> time you are asked. To exit this, you only have to input an empty string,
> that is to press the ENTER key. And here is the trouble. The program will
> not stop this looping, unless you enter several empty words.
>
> Here is the snip of the program that is causing trouble:
>
> procedure lookup;
> begin
>     writeln;
>     write('please enter word to be looked up: ');
>     readln( s ); { s : STRING; }
>     if s = '' then exit; { this doesn't work,
>                            unless running a couple of
>     assign(f,'wordlist.dat'); reset(f);
>     repeat
>          read(f,t); { t : STRING }
>          if t = s then found := true   else found := false; {found :
BOOLEAN}
>     until eof(f);
>     close(f); {f : FILE OF STRING}
>     if not found then begin
>          writeln('the word ', s, 'is not found in the list');
>          lookup;

Why are you calling lookup recursively here? That would be your problem. You
would be better off redefining Lookup as a function returning a boolean, and
then calling it in a non-recursive loop.
Something like...

Repeat
  readln(s);
  If s='' then
exit;
  if Lookup(s) then
    writeln(s,' found')
  else
    writeln(s,' not found');
until false;

Recursion is useful for some things but should generally be avoided wherever
possible, especially until you have more experience.

FP
Technical Details
Message-ID: <8g0soc$ssb$1@kermit.esat.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <D0OU4.6707$C9.118410@news1.online.no>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1097b9,1d4aea8798c741f5
X-Google-Attributes: gid1097b9,public
X-Google-Thread: 111659,1d4aea8798c741f5
X-Google-Attributes: gid111659,public
From: "Frank Peelo" <fpeelo@indigo.ie>
Subject: Re: WHAT COULD BE WRONG?
Date: 2000/05/18
Message-ID: <8g0soc$ssb$1@kermit.esat.net>
X-Deja-AN: 624986940
References: <D0OU4.6707$C9.118410@news1.online.no>
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
X-Complaints-To: abuse@esat.net
X-Trace: kermit.esat.net 958658124 29579 193.120.140.50 (18 May 2000 13:55:24 GMT)
Organization: Esat Net  
X-MSMail-Priority: Normal
NNTP-Posting-Date: 18 May 2000 13:55:24 GMT
Newsgroups: comp.lang.pascal.borland,dk.edb.programmering.pascal