DWScript provides several reserved keywords to alter the flow of execution by jumping out of loops or subroutines. Unlike traditional Pascal where some of these might be system procedures, in DWScript they are first-class keywords.
The exit keyword immediately terminates the execution of the current subroutine (procedure or function).
In a procedure, exit simply returns control to the caller.
procedure Process(value : Integer);
begin
if value < 0 then
exit; // Stop processing
PrintLn(value);
end; In a function, exit can be used to return a value immediately. DWScript supports several syntaxes for this, highlighting its status as a keyword:
Result and call exit.exit.exit followed by the value (no parentheses).function Calculate(x : Integer) : Integer;
begin
// Method 1: Standard
if x = 0 then begin
Result := 0;
exit;
end;
// Method 2: Parentheses (Delphi style)
if x = 1 then
exit(10);
// Method 3: DWScript Keyword style
if x = 2 then
exit 20;
Result := x * 10;
end;
PrintLn(Calculate(0));
PrintLn(Calculate(1));
PrintLn(Calculate(2));
PrintLn(Calculate(3)); 0 10 20 30
Using exit in the global scope (outside of any subroutine) immediately terminates the execution of the entire script.
var stopEarly := True;
PrintLn('Starting script...');
if stopEarly then
exit;
PrintLn('This might not be reached.'); Starting script...
The break keyword immediately terminates the innermost loop (for, while, or repeat) that contains it. Execution resumes at the statement following the loop.
var found := False;
for var i := 1 to 10 do begin
if i = 5 then begin
found := True;
break; // Stop the loop
end;
PrintLn(i);
end; 1 2 3 4
The continue keyword skips the remainder of the current iteration of the innermost loop and proceeds to the next iteration.
for loop, the counter is incremented/decremented.while or repeat loop, the condition is re-evaluated.for var i := 1 to 5 do begin
if i = 3 then
continue; // Skip 3
PrintLn(i);
end; 1 2 4 5