这个Pascal语法出了什么问题?

时间:2012-09-26 14:43:19

标签: pascal

我无法理解这里发生了什么。你能帮我个忙吗?这是有问题的代码:

While not EOF(Archi) do begin
  index:= index + 1;
  Read(Archi, Alumno[index]);
  Promes[index] := (Alumno[index].nota1 + Alumno[index].nota2) / 2;
  if Promes[index] >= 6 then begin
     alguPromo := true;
     PromosIndex := PromosIndex + 1;
     Promos[PromosIndex]:= Alumno[index];
  end;
  else begin
       if Promes[index] > 4 then cantiRecu:= cantiRecu + 1;
       else begin
            LibresIndex += 1;
            Libres[LibresIndex] := Alumno[index];
            end;
  end;
end;

编译器在此代码的第10行标记错误(否则开始)。错误是:     致命:语法错误,;预期但是ELSE找到了。

如果有人想托盘编译,请输入整个代码:http://pastebin.com/dRg1Lguu

2 个答案:

答案 0 :(得分:6)

请注意,在Pascal中,分号是分隔符,而不是终结符。有时候这并不重要,但在某些情况下确实如此,特别是在else之前。你的代码应该是:

while not EOF(Archi) do
  begin
    index:= index + 1;
    Read(Archi, Alumno[index]);
    Promes[index] := (Alumno[index].nota1 + Alumno[index].nota2) / 2;
    if Promes[index] >= 6 then
      begin
        alguPromo := true;
        PromosIndex := PromosIndex + 1;
        Promos[PromosIndex] := Alumno[index]
      end
    else
      begin
        if Promes[index] > 4 then
          cantiRecu:= cantiRecu + 1
        else
          begin
            LibresIndex := LibresIndex + 1;
            Libres[LibresIndex] := Alumno[index]
          end
      end
  end

请注意,我已经将代码重新格式化为更传统的样式,这有助于使程序逻辑更容易理解,这也使得分号需要的地方和不需要分号的地方更加明显。

答案 1 :(得分:0)

在+ =运算符

中看起来像问题