Delphi – E2032 For loop control variable must have ordinal type

A for loop’s control variable in delphi must be of the types Boolean, Char, WideChar, Integer, Enumerated, or Subrange.

program Produce;
var
  x: Real;
begin (*Plot sine wave*)
  for x := 0 to 2*pi/0.2 do                            (*<-- Error message here*)
    Writeln( '*': Round((Sin(x*0.2) + 1)*20) + 1 );
end.

The for loop control variable in the example is of type Real, which is not allowed.

How to fix it?

program Solve;
var
  x: Integer;
begin (*Plot sine wave*)
  for x := 0 to Round(2*pi/0.2) do
    Writeln( '*': Round((Sin(x*0.2) + 1)*20) + 1 );
end.

Use the Integer ordinal type instead.

If you utilise an Int64 or Variant control variable in a FOR loop, you can get this error. This is due to a compiler constraint, which may be overcome by replacing the FOR loop with a WHILE loop.