'THEN' expected
Velox reports 'THEN' expected when it has parsed the condition following if but the next token is not the then keyword. then separates the Boolean condition from the single statement or begin..end block controlled by that condition.
Example
procedure ScriptEvent(var Value: Variant);
begin
if Value = ''
Value := 'default'; // Error: 'THEN' expected
end;
Add the keyword after the complete condition:
if Value = '' then
Value := 'default';
How Velox detects it
ProcessIf advances past if and asks the expression compiler to calculate up to token then. If an expression is produced but the current token is not then, it frees the temporary expression and emits ecThenExpected. Only this if compiler path emits the diagnostic.
After accepting then, the compiler writes the condition into its Boolean working register and emits the conditional branch. A condition that cannot be converted to the registered Boolean type can therefore report Type mismatch after the keyword issue is fixed.
Correction procedure
- Check that the condition before the reported token is complete.
- Balance any parentheses and finish comparisons or function calls.
- Add
thenimmediately before the controlled statement. - For multiple controlled statements, enclose them in
begin..end. - In an
if..then..else, do not put a semicolon immediately beforeelse.
Edge cases and quirks
- A malformed condition can emit another expression diagnostic before the compiler reaches this check.
- Newlines have no special terminating meaning;
thenis still required even when the controlled statement starts on the next line. - Nested
ifstatements associate eachelsewith the nearest unmatchedif; usebegin..endto make a different structure explicit. - Velox enables short-circuit Boolean evaluation, but that affects runtime operand evaluation, not the requirement for
then.
Related reference
if- conditional-statement syntax and execution.if..else- branch association and semicolon rules.Semicolon (';') expected- statement separation after the complete conditional.Type mismatch- the parsed condition is not Boolean-compatible.