/
How to use operators in SIL scripts

How to use operators in SIL scripts

These examples illustrate the versatility of arithmetic operators beyond basic addition and subtraction, revealing their broader applications and potential within SIL scripting.

Arithmetic operators

SIL supports the standard operators, such as +, -, *, /, and %. These operators can be used on more than just numbers. Depending on the data types involved, these operators behave differently - they can concatenate strings, add time to dates, multiply intervals, and more. This flexibility makes arithmetic operators powerful tools for data manipulation across various data types.

Example 1

number surcharge = 2.50; number rebate = 1.00; number discount = 10; number total = 10; total = total + surcharge; total = total - rebate; total = total - (total * (discount/100)); return total;

Example 2

string someText = "Hello "; someText = someText + "World!"; someText = someText - "World"; return someText; //returns "Hello !";

Example 3

date duration = (dueDate + "2w") - startDate;

Example 4

interval day = "24h"; interval month = day * 30;d

Logical operators

Logical operators, such as && for AND, || for OR, and ! for NOT, used to construct comparison statements. They let you create complex conditions by combining or negating simpler expressions, as demonstrated in these examples.

Example 1: AND

if(1 == 1 && 2 == 2) { return true; }

Example 2: OR

if(animal == "Cat" || animal == "Dog") { return "Pet"; }

Example 3: NOT

if(!direction == "Up") { return "Down" }

Related content