qmesa qmesa - 4 months ago 8
Pascal Question

Using multiple if/else statements in a Repeat Until loop

I am trying to use multiple if/else statements within a Repeat Until loop (Pascal.) I get an error saying the compiler expects the Until statement after the first If clause is done.

How can I nest the other if/else statements into the loop?

program adventureTime;
uses crt; (** for debug purposes. it allows the use of the readkey function **)

var
playerName, inputAnswer : string;
gameCounter : integer;

begin
(** INTRODUCTION **)
gameCounter := 0;

repeat
writeln('Hello adventurer. What is thy name? ');
readln(playerName);

writeln('It is nice to meet you ', playerName, '.');
writeln('Are you ready for an adventure? (yes/no/maybe)');

readln(inputAnswer);

if (inputAnswer = 'no') then
writeln;
writeln('Wrong answer! Try again!');
writeln;
gameCounter := 0;

else if (inputAnswer = 'yes') then
writeln;
writeln('Great! Get ready for the adventure of a lifetime!');
writeln;
gameCounter := 2;

else if (inputAnswer = 'maybe') then
writeln;
writeln('Make up your mind, fool!');
writeln;
gameCounter := 0;

else
writeln;
writeln('That was not one of the options!');
writeln;
gameCounter := 0;

until gameCounter <> 0;


writeln('out of bounds');
readkey;

end.

Answer

not sure, but doesn't an if else statement in pascal look like this:

if ... then
begin
.
.
.
end 
else if...