DWScript supports standard Pascal operators for arithmetic, logic, and comparisons.
var a := 10;
var b := 20;
PrintLn(a + b);
PrintLn(10 div 3);
PrintLn(10 mod 3);
PrintLn(10 / 3); 30 3 1 3.33333333333333
| Operator | Operation | Example |
|---|---|---|
+ |
Addition | 1 + 2 (3) |
- |
Subtraction | 5 - 3 (2) |
* |
Multiplication | 2 * 4 (8) |
/ |
Division (Float) | 10 / 2 (5.0) |
div |
Integer Division | 10 div 3 (3) |
mod |
Modulus (Remainder) | 10 mod 3 (1) |
Used with Boolean values. Logical operators in DWScript are short-circuiting, meaning the second operand is only evaluated if the first one doesn't determine the final result.
| Operator | Description |
|---|---|
not |
Negation (True becomes False) |
and |
Logical AND (True if both are True) |
or |
Logical OR (True if either is True) |
xor |
Logical XOR (True if only one is True) |
implies |
Material Implication (False only if True implies False) |
| Operator | Description |
|---|---|
= |
Equal to |
<> |
Not equal to |
< |
Less than |
> |
Greater than |
<= |
Less than or equal to |
>= |
Greater than or equal to |
is |
Type compatibility check (for classes and interfaces) |
as |
Checked type cast |
implements |
Checks if an object/class implements an interface |
in |
Set membership, array inclusion, or substring check |
not in |
Negation of in (True if NOT a member) |
In DWScript, the in operator is highly versatile and works with sets, arrays, and strings.
You can check if a value belongs to a set of values or a specific range.
var c := 'k';
if c in ['a'..'z', '0'..'9', '_'] then
PrintLn('Is Alphanumeric');
var x := 5;
if x in [1..10, 20..30] then
PrintLn('Is in range');
var s := 'Grape';
if s in ['Apple'..'Orange'] then
PrintLn('Between Apple and Orange'); Is Alphanumeric Is in range Between Apple and Orange
You can check if an element exists within an array. This works for simple types, records, and objects.
var colors := ['Red', 'Green', 'Blue'];
if 'Green' in colors then
PrintLn('Found Green');
if 'Yellow' not in colors then
PrintLn('Yellow is missing'); Found Green Yellow is missing
You can check if a string contains another string using the in operator or the .Contains() method. This is more readable and idiomatic than using Pos() > 0.
var msg := 'Hello World';
// Using 'in' operator
if 'World' in msg then
PrintLn('Found using in');
// Using .Contains method
if msg.Contains('Hello') then
PrintLn('Found using .Contains');
// Legacy style (not recommended)
if Pos('Hello', msg) > 0 then
PrintLn('Found using Pos'); Found using in Found using .Contains Found using Pos
Higher priority operators are evaluated first. When operators have the same priority, they are evaluated from left to right.
not, Unary -*, /, div, mod, and, shl, shr, sar, %?? (Coalesce)+, -, or, xor=, ==, <>, !=, <, >, <=, >=, in, not in, is, as, impliesif then else (Ternary)You can define custom behavior for operators when working with your own types.
+=, in) for classes.DWScript also supports several specialized operators for concise expression:
if then else.??.+=, ==, and ===.