我想在Repeat Until循環(Pascal。)中使用多個if/else語句我得到一個錯誤,指出編譯器期望Before語句在第一個If子句之後完成。在Repeat Until循環中使用多個if/else語句
如何將其他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.
參見[這個答案](http://stackoverflow.com/a/28221465/62576)有關if和begin/end的教程。 –
[Pascal適當的結構語法,如果開始結束和; (在Inno Setup中)](http://stackoverflow.com/questions/28221394/proper-structure-syntax-for-pascal-if-then-begin-end-and-in-inno-setup) –
謝謝,肯!我能夠通過將您發送的教程與此帖子中的其他答案相結合來解決我的問題。 – qmesa