我和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语句的地方。已经很晚了,我整天都在工作,所以我可能只是累了。有人可以帮忙吗?
答案 0 :(得分:6)
试试这个
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;
答案 1 :(得分:1)
因为“else if”不正确。使用“elsif”。