问题描述:

Fatal error while trying to compile "until" expected found "else", cant seem to get how to fix it

......

 begin

divisor:= 2;

cont:= 0;

write(i,':');

repeat

if (i mod divisor = 0) then

begin

write(' divisor ');

divisor:=succ(divisor);

cont:=succ(cont);

end;

else

divisor:=succ(divisor);

until (cont = 6) or (divisor>i div 2)

writeln();

end;

end;

end.

网友答案:

The issue is that you have a semicolon after end; before else. That basically terminates the if statement so the else becomes an else to repeat (which obviously isn't valid). The fix is to remove the semicolon after end;

See this for reference: http://wiki.freepascal.org/Else

Fix:

  if (i mod divisor = 0) then
     begin
       write(' divisor ');
       cont:=succ(cont);
     end
  else
    divisor:=succ(divisor);
相关阅读:
Top