这个 if else 语句有什么问题?
What is wrong with this if else statement?
我正在使用 Ada,控制语句中缺少大括号让我有点困惑。我写了以下 if-else 语句:
if i = 1 then
largest := nextInteger;
else if i = 2 then
if nextInteger > largest then
secondLargest := largest;
largest := nextInteger;
else
secondLargest := nextInteger;
end if;
else
if nextInteger > largest then
secondLargest := largest;
largest := nextInteger;
else if largest > nextInteger and then nextInteger > secondLargest then
secondLargest := nextInteger;
end if;
end if;
我收到的错误消息是:
program_one.adb:15:05: missing "end if:" for "if" at line 3
program_one.adb:15:05: missing "end if;" for "if" at line 1
我正在努力寻找我没有关闭 if 语句的地方。很晚了,我已经工作了一整天,所以我可能只是累了。有人可以帮忙吗?
这样试试
if i = 1 then
largest := nextInteger;
elsif i = 2 then
if nextInteger > largest then
secondLargest := largest;
largest := nextInteger;
else
secondLargest := nextInteger;
end if;
else
if nextInteger > largest then
secondLargest := largest;
largest := nextInteger;
elsif largest > nextInteger and then nextInteger > secondLargest then
secondLargest := nextInteger;
end if;
end if;
因为"else if"不正确。使用 "elsif".
我正在使用 Ada,控制语句中缺少大括号让我有点困惑。我写了以下 if-else 语句:
if i = 1 then
largest := nextInteger;
else if i = 2 then
if nextInteger > largest then
secondLargest := largest;
largest := nextInteger;
else
secondLargest := nextInteger;
end if;
else
if nextInteger > largest then
secondLargest := largest;
largest := nextInteger;
else if largest > nextInteger and then nextInteger > secondLargest then
secondLargest := nextInteger;
end if;
end if;
我收到的错误消息是:
program_one.adb:15:05: missing "end if:" for "if" at line 3
program_one.adb:15:05: missing "end if;" for "if" at line 1
我正在努力寻找我没有关闭 if 语句的地方。很晚了,我已经工作了一整天,所以我可能只是累了。有人可以帮忙吗?
这样试试
if i = 1 then
largest := nextInteger;
elsif i = 2 then
if nextInteger > largest then
secondLargest := largest;
largest := nextInteger;
else
secondLargest := nextInteger;
end if;
else
if nextInteger > largest then
secondLargest := largest;
largest := nextInteger;
elsif largest > nextInteger and then nextInteger > secondLargest then
secondLargest := nextInteger;
end if;
end if;
因为"else if"不正确。使用 "elsif".