HomeDelphiDelphi Error – E2032 For loop control variable must have ordinal type

Delphi Error – E2032 For loop control variable must have ordinal type

Delphi Compiler Error

E2032 For loop control variable must have ordinal type

Reason for the Error & Solution

The control variable of a for loop must have type Boolean, Char, WideChar, Integer, an enumerated type, or a subrange type.

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 example uses a variable of type Real as the for loop control variable, which is illegal.

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.

Instead, use the Integer ordinal type.

You may see this error if a FOR loop uses an Int64 or Variant control variable. This results from a limitation in the compiler which you can work around by replacing the FOR loop with a WHILE loop.

Share:

Leave a Reply

You May Also Like

Delphi Compiler Error X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...