What's wrong with this Pascal syntax?

梦想与她 提交于 2019-12-02 12:26:52

问题


I can't understand what's going on here. Can you give me a hand? This is the problematic code:

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;

The compiler marks error in the line 10 of this code (else begin). The error is: Fatal: Syntax error, ; expected but ELSE found.

If someone wants to tray compile here is the entire code: http://pastebin.com/dRg1Lguu


回答1:


Note that in Pascal the semicolon is a separator, not a terminator. Sometimes this doesn't matter, but in some cases it does, particularly before an else. Your code should be:

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

Note that I have re-formatted the code into a more conventional style which helps to make the program logic more easily understood and which also makes it more obvious where the semicolons are needed and where they are not.




回答2:


Looks like problem in += operator



来源:https://stackoverflow.com/questions/12604323/whats-wrong-with-this-pascal-syntax

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!