-1

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. 
R.FALLEN
  • 11
  • 3
  • If you'd properly format your code, you might have seen the error yourself. And well, error messages are usually right. – Rudy Velthuis Sep 14 '16 at 22:15
  • You can also read one of my old [answers](http://stackoverflow.com/a/32933320/5043424) about alike issue. – asd-tm Sep 15 '16 at 13:35

1 Answers1

5

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);
Rudy Velthuis
  • 28,387
  • 5
  • 46
  • 94
Haukman
  • 3,726
  • 2
  • 21
  • 33