Syntax Guide: Operators

August 15, 2016

Designer has built-in operators that can be used in enabling conditions or validations. This article explains the following operators that you can use in your instrument:

 

Arithmetic Operators

 

The following table shows the arithmetic operators supported by Survey Solutions. Arithmetic expressions are evaluated from left to right. For the example, assume A = 20 and B = 10

 

OperatorDescriptionExample
+Addition: returns the sumA + B = 35
-Subtraction: returns the differenceA - B = 10
*Multiplication: returns the productA * B = 200
/Division: returns the quotientB / A = 2
%Modulus: returns the remainder after an integer divisionB % A = 0
(The remainder of 20 divided by 10 is 0)

 

 

Relational Operators 

 

These operators compare two values and return either TRUE or FALSE. The following comparison operators are supported by Survey Solutions:
 

OperatorDescriptionExample
==Checks if the two values are equal. If values are equal, then the condition is true20 == 10 returns FALSE
!=Checks if the two values are not equal. If the values are not equal, then the condition is false20 != 10 returns TRUE
>Checks if the left value is greater than the right value20 > 10 returns TRUE
<Checks if the left value is less than the right value20 < 10 returns FALSE
>=Checks if the left value is greater than or equal to the right value20 >= 10 returns TRUE.
10 >= 10 returns TRUE.
<=Checks if the left value is less than or equal to the right value20 <= 10 returns FALSE.
10 <= 10 returns TRUE.

 

 

 

 

 

Logical Operators

 

Logical values returns either TRUE or FALSE. The following tables show the logical operators supported by Survey Solutions: 

 

OperatorDescriptionExample
&&Logical AND operator.
A && B returns true of both expression A and B are true.
(20 == 10) && (10 > 5) returns FALSE
(10 == 10) && (10 > 5) returns TRUE
||Logical OR operator
A || B returns true if either expression A or expression B is true
(20 == 10) || (10 > 5) returns TRUE
(20 == 10) || (10 < 5) returns FALSE
!Logical NOT operator
!A returns true if expression A is false. It returns false if expression A is true.
!(20 == 10) returns TRUE
!(10 == 10) returns FALSE

 

 

 

 

Other Useful Operators

 

 

These are other operators that you might want to use in your Survey Solutions instrument.

 

OperatorDescriptionExample
?:Conditional Expression/ The condition must evaluate to true or false. If condition is true, the first expression is evaluated and becomes the result. If condition is false, the second expression is evaluated and becomes the result. Only one of the two expressions is evaluated.(10 < 2)? a:b will return b
(10 > 2)? a:b will return a