0
votes

I have problems with my pascal code.

When compiling it shows me the error: syntax : until expected but end found.

PROGRAM EvilGOTO;
Var rand,count,guess : integer;
LABEL correct, schleife, wrong, ende;

begin
    Randomize;
            count :=0;
            repeat
                    schleife:
                    count := count+1;
                    rand := Random(10);
                    guess := Random(10);
                    if rand=guess
                    then
                            writeln('Correct')
                            end
                    else
                            writeln('False Guess')
                            goto schleife
             until
             count = 10;
end.    

can you help me?

1
if..then..end is the problem. That end after writeln('Correct'). - TLama
Best to avoid goto. Try to come up with another way to exit the loop on that else. - Al Lelopath
A side note: you seem to be using the goto to create a loop, but you are using it inside a loop (repeat ... until). That's perfectly superfluous and, when you've fixed the issue mentioned by @TLama, you can try and get rid of the goto (as well as the corresponding label). - Andriy M
can you pls help me to optimize this code?:) - GOTO

1 Answers

2
votes
PROGRAM EvilGOTO;
Var rand,count,guess : integer;
begin
    Randomize;
    count :=0;
    repeat
      rand := Random(10);
      guess := Random(10);
      if rand=guess then
         writeln('Correct')
         else
         begin
           count := count+1;
           writeln('False Guess');
         end
    until count = 10 or rand=guess;
end.