Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5999149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:30:40+00:00 2026-05-23T00:30:40+00:00

you’ve all been so helpful so far, so heres another annoying problem for you!

  • 0

you’ve all been so helpful so far, so heres another annoying problem for you!

I’ve got a basic word guessing game, written in Pascal for a console in Delphi 7, where the guesses (right or wrong) are stored in a fixed array named “guesses” now what i need to do is test to see if they have guessed that letter already. I have the following code…

Write ('Guess a letter: ');
Readln (guess);
Guess := UpCase(Guess);
repeat
  for i := 1 to 20 do
  begin
    if guess = guesses[i] then
      begin
        guessed := true;
      end
    else begin
      guessed := false;
    end;
  end;
until (guessed = true) or (i = 20) ;

My problem is it follows the for loop 20 times, and should end as it is the first letter and is not in the “guesses” array, but keeps repeating. after its looped the for loop 20 times and found no entry of the guess letter, it should exit with the boolean “guessed” as false.

Thanks in advance for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:30:41+00:00Added an answer on May 23, 2026 at 12:30 am

    The code you have written makes no sense.

    1. To exit the for loop when you find your guess, add a break below the guessed := true.

    2. Why are you repeating the same logic infinitely using one condition that will always be true, and one condition that might easily be never true? I’m guessing you’ve shown part of your code inside that repeat loop, and not all of it. In that case, a good convention on stackoverflow for code samples is to put in something like: do_something_here(); in the place where you really have 100 more lines you didn’t want to show here.

    3. It would be great if you showed the var declarations so we can see your types.

    Your code would make sense again if:

    1. You break from the for loop.
    2. You only need to do the While loop if you do something variant in each case, such as ask the user to input some new input.

    here’s some code that does something at least useful:

    (1) it will ask you to enter something, and repeat until you enter something that matches an element in the hard coded list.

    (2) It will terminate, given certain inputs from you, unlike your code which may never terminate. It also doesn’t waste time in the for loop on the other elements once it finds a match.

    (3) It shows trivially that you should validate the inputs, or you will have exceptions. What if you entered nothing and just hit enter in your code? You would get an endless loop.

    procedure Demo;
    var
      guess:Char;
      guesses:Array of Char;
      i: Integer;
      guessed:Boolean;
    begin
     repeat
      setup_guesses(guesses); // not shown
      Write ('Guess a letter: ');
      Readln (guess);
      Guess := UpCase(Guess);
      if (Ord(Guess)>='A') and (Ord(Guess)<='Z') then begin
       guessed := false;
       for i := Low(guesses) to High(Guesses) do // why hard code 1..20???
       begin
         if guess = guesses[i] then
           begin
             guessed := true;
             break;
           end;
       end;
      end;
     until (guessed = true);
     if guessed then
       WriteLn('An element in guesses matched your input')
     else
       WriteLn('No element in guesses array matches your input')
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I need to clean up various Word 'smart' characters in user input, including but
i got an object with contents of html markup in it, for example: string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.