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.