'DO' expected
Velox reports 'DO' expected after the controlling part of a for, while or with statement when the required do keyword is absent.
Required forms
for Index := First to Last do
Statement;
while Condition do
Statement;
with RecordOrObject do
Statement;
A repeat ... until Condition loop does not use do.
Example
procedure ScriptEvent(var Value: Variant);
var
Index: Integer;
begin
for Index := 1 to 3 // Error: 'DO' expected
Value := Index;
end;
Add the keyword between the loop range and body:
for Index := 1 to 3 do
Value := Index;
Use a compound statement when the body contains several statements:
while HasMore do
begin
ReadNext;
ProcessCurrent;
end;
How Velox detects it
The modified PascalScript compiler emits ecDoExpected in ProcessFor, ProcessWhile and ProcessWith after their control expression has been parsed. Velox reports the current token where do should have appeared.
If the control expression is incomplete, the highlighted first body token may be a consequence rather than the root cause. Check missing parentheses, the to/downto keyword and the loop-control assignment before inserting do mechanically.
Common causes
- Omitting
doafter aforrange orwhilecondition. - Writing
then, copied from anifstatement. - Adding
doto arepeatloop and thereby shifting later parsing. - Starting the loop body before completing the condition.
- Forgetting
doafter awithexpression because it is not visually a loop.
Correction procedure
- Identify the owning
for,whileorwithkeyword. - Complete its control clause first.
- Add exactly one
dobefore the body statement. - Wrap a multi-statement body in
begin..end. - Recompile and resolve the earliest remaining structural diagnostic.
Related reference
for loop—:=,to/downtoand counter behaviour.while loop— pre-test condition behaviour.repeat loop— the loop form that does not usedo.with— record/class member context.