这个 Pascal 语法有什么问题? [英] What's wrong with this Pascal syntax?

查看:54
本文介绍了这个 Pascal 语法有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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;

编译器在此代码的第 10 行中标记错误(否则开始).错误是:致命:语法错误,;预期但其他发现.

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

如果有人想托盘编译这里是完整的代码:http://pastebin.com/dRg1Lguu

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

推荐答案

请注意,在 Pascal 中,分号是 分隔符,而不是 终止符.有时这无关紧要,但在某些情况下确实如此,尤其是在 else 之前.您的代码应该是:

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.

这篇关于这个 Pascal 语法有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆