Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
If statement 这个if-else语句有什么错?_If Statement_Nested_Ada - Fatal编程技术网

If statement 这个if-else语句有什么错?

If statement 这个if-else语句有什么错?,if-statement,nested,ada,If Statement,Nested,Ada,我和Ada一起工作,控制语句中缺少大括号让我有点困惑。我已编写了以下if else声明: if i = 1 then largest := nextInteger; else if i = 2 then if nextInteger > largest then secondLargest := largest; largest := nextInteger; else secondLargest := nextInt

我和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;
像这样试试

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;

因为“elseif”是不正确的。使用“elsif”。

因为“elseif”不正确。使用“elsif”。

然后使用nextInteger>secondmagest,然后使用nextInteger>secondmagest
您要先删除没有删除错误消息的
然后删除
。“然后”是短路和操作-只有在第一部分为真的情况下才执行第二部分。短路或短路有相应的“or else”。因此,在之后去掉“then”并没有给出任何特别的信息,尽管除非你真的需要,否则你不应该使用短路形式。注意,谢谢。
然后是nextInteger>第二大然后
你想先去掉没有去掉错误信息的
然后
。“然后”是短路和操作-只有在第一部分正确的情况下才执行第二部分。短路或短路有相应的“or else”。因此,在之后去掉“then”并没有给出任何特别的信息——尽管除非你真的需要,否则你不应该使用短路形式。注意,谢谢你。@mpowell 48:你拼写错误了
elsif
;请参阅@mpowell48:您拼写错误了
elsif
;看见