在 Repeat Until 循环中使用多个 if/else 语句
Using multiple if/else statements in a Repeat Until loop
我正在尝试在 Repeat Until 循环 (Pascal) 中使用多个 if/else 语句。我收到一条错误消息,提示编译器在第一个 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.
不确定,但 Pascal 中的 if else 语句不是这样的:
if ... then
begin
.
.
.
end
else if...
我正在尝试在 Repeat Until 循环 (Pascal) 中使用多个 if/else 语句。我收到一条错误消息,提示编译器在第一个 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.
不确定,但 Pascal 中的 if else 语句不是这样的:
if ... then
begin
.
.
.
end
else if...