'TO' expected
Velox reports 'TO' expected after it has parsed the counter and initial value of a for statement but cannot find either direction keyword. Despite the message naming only TO, the compiler accepts both to and downto.
Syntax
for Counter := InitialValue to FinalValue do
Statement;
for Counter := InitialValue downto FinalValue do
Statement;
Example
This loop omits its direction:
procedure ScriptEvent(var Value: Variant);
var
I: Integer;
begin
for I := 1 3 do // Error: 'TO' expected
Value := I;
end;
Add to for an ascending loop or downto for a descending loop:
procedure ScriptEvent(var Value: Variant);
var
I: Integer;
begin
for I := 1 to 3 do
Value := I;
end;
How Velox detects it
The for compiler performs these steps in order:
- Resolve the counter as writable variable storage.
- Require
:=and parse the initial-value expression. - Test the next token for
toordownto. - Emit
ecToExpectedif neither token is present. - Parse the final-value expression and then require
do.
The diagnostic therefore points at the token after the initial value. A malformed initial expression can move that detection point or produce a more specific expression error first.
Correction procedure
- Check that the statement begins
for Counter := InitialValue. - Insert exactly one direction keyword:
toto increment ordowntoto decrement. - Supply the final value after the direction.
- Check for the separate
dokeyword before the loop body.
Edge cases and quirks
- The public message is inherited from PascalScript and says only
'TO' expected;downtois equally valid. - A misspelling such as
downToValueis an identifier, not thedowntokeyword, and triggers this diagnostic at that token. - Velox accepts integer-sized counters, enumeration counters and
Variantcounters in this compiler path. Unlike Delphi's general ordinal rule, the current counter-type check does not includeChar; a character counter producesType mismatchrather than'TO' expected. - An invalid counter, initial value or final value produces
Variable ExpectedorType mismatch. Addingtodoes not correct those separate faults. - The initial and final expressions are compiled before the loop body. The final expression is evaluated once when the loop starts, and Velox emits a boundary check to avoid wrapping an integer counter after its highest or lowest value.
- This is a compile-time error. The loop body does not execute partially.
Related reference
DO expected- the loop direction is present but the body separator is missing.Type mismatch- the counter or a bound has an unsupported type.Variable Expected- the counter is not writable variable storage.