在Repeat Until循环中使用多个if / else语句

时间:2016-07-25 00:31:53

标签: pascal

我试图在Repeat Until循环中使用多个if / else语句(Pascal。)我得到一个错误,说编译器在第一个If子句完成后需要Until语句。

如何将其他if / else语句嵌套到循环中?

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.

1 个答案:

答案 0 :(得分:0)

不确定,但是pascal中的if else语句看起来不像这样:

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