Not in a loop
Velox reports Not in a loop when break or continue appears without an active loop target. Both statements are compiled as jumps whose destination is supplied by the surrounding for, while or repeat compiler.
Example
procedure ScriptEvent(var Value: Variant);
begin
if Value = '' then
break; // Error: Not in a loop
end;
Use exit to leave the current procedure, or put break inside the loop it is intended to end:
procedure ScriptEvent(var Value: Variant);
begin
while Value <> '' do
begin
if Value = 'stop' then
break;
Value := Copy(Value, 2, Length(Value));
end;
end;
How Velox detects it
While compiling a loop, PascalScript creates lists for unresolved break and continue bytecode offsets. Outside a loop, that target context is absent. ProcessSub recognises either keyword, sees no active offset list and emits ecNotInLoop.
Inside a loop, the compiler also emits cleanup operations for nested try, except, finally and with state before writing the jump. It later patches break to the loop end and continue to the loop's next-test or increment point.
Correction procedure
- Decide whether the intended target is a loop, the current routine or an enclosing business operation.
- Use
breakonly to end the nearest active loop. - Use
continueonly to start the next iteration of the nearest active loop. - Use
exitto leave the current procedure; do not substitute it mechanically when later cleanup or statements are required.
Edge cases and quirks
- An
if,case,begin..endortryblock does not by itself provide a loop target. - In nested loops,
breakandcontinueapply only to the nearest loop. breakandcontinueare recognised case-insensitively through the identifier path.- Unlike Delphi's separate restriction on leaving a
finallyclause, this compiler path only tests whether a loop target exists. When a transfer leaves active exception orwithstate, Velox emits cleanup operations before the jump. Treat this as a Velox implementation detail, not portable Delphi syntax. - This is a compile-time error; no partial iteration occurs.
Related reference
for- counted-loop control.while- pre-test loop control.repeat..until- post-test loop control.Invalid jump- agotocrosses a protected structured region.