Operators

Prior | Next

Operators are the symbols in your script that enable you to manipulate all types of data. There are operators for adding and subtracting numeric data as an example.

Assignment Operator
Perhaps one of the toughest things to get used to is the ESPL assignment operator. To assign a value to a variable use the := operator. Example:

  MyIntegerVariable := 5;
  MyStringVariable := 'This is a string of characters';

Comparison Operators
ESPL uses the = operator to perform logical comparisons between two expressions or values. Example:

  if x = y then DoSomething;

Remember that in ESPL, the := operator is used to assign a value to a variable, and the = operator compares the values of two operands.

ESPL's not-equal-to operator is <>. Example:

  if x <> y then DoSomething;

Logical Operators
ESPL uses the words and and or as logical and and or operators. The most common use of these operators is as part of an if statement, such as in the following two examples:

  if Condition1 and Condition2 then DoSomething;
  if Condition1 or Condition2 then DoSomething;

ESPL's logical not operator is the word not. It is used to check a comparison for a false condition as in this example:

  if not Condition1 then DoSomething;

Arithmetic Operators
The ESPL arithmetic operators should feel familiar to you. They are + for addition, - for subtraction, * for multiplication, and / for floating-point division. ESPL also uses the word div as the operator for integer division. ESPL has different division operators for floating-point and integer math. The div operator automatically truncates any remainder when dividing two integer expressions.

In evaluating expressions, there is an order of precedence as to which operators are evaluated first. When in doubt, use parentheses to control the order of evaluation. Consider these two example:

  MyVariable := 2 + 4 / 2 + 1;
  {This evaluates to 2 + 2 + 1 = 5 because division has a higher precedence than addition.}

  MyVariable := (2 + 4) / (2 + 1);
  {This evaluates to 6 / 3 = 2 because the ( ) expressions are evaluated before the division}

Prior | Next