Boolean and conditional logic functions

  • Updated

Using NetScript in Optimizely Analytics, you can perform boolean and conditional logic operations.

if..then..else

Define a sequence of conditional statements. The result corresponds to the first true condition. The else value is optional, and the default result is null.

Function:

if condition1 then result1 [else if condition2 then result2...] [else resultN] end

Data type: input type

Example:

if 'test' == 'test' then true else if 'test2' == 'test2' then true else false end
if “test” == “test1” then “test1 success” else if “test2” == “test2” then “test 2 success” end

Result:

true
test 2 success

not (bool1)

Return the boolean negation of bool1.

Function:

not (bool1)

Data type: boolean

Example:

not ('a' == 'b')
not ('a' != 'b')

Result:

true
false

bool1 or bool2

Determine whether bool1 or bool2 is true.

Function:

bool1 or bool2

Data type: boolean

Example:

'a' != 'b' or 'a' == 'b'
'a' == 'b' or 'a' == 'b'

Result:

true
false

bool1 and bool2

Determine whether both bool1 and bool2 are true.

Function:

bool1 and bool2

Data type: boolean

Example:

'a' == 'a' and 'b' == 'b'
'a' != 'b' and 'a' == 'b'

Result:

true
false

input1 == input2

Check whether input1 and input2 are equal.

Function:

input1 == input2

Data type: boolean

Example:

'snow' == 'snow'
'snow' == 'food'

Result:

true
false

input1 != input2

Check whether input1 and input2 are unequal.

Function:

input1 != input2

Data type: boolean

Example:

'snow' != 'food'
'snow' != 'snow'

Result:

true
false

input1 < input2

Check whether the value of input1 is less than input2.

Function:

input1 < input2

Data Type: boolean

Example:

57 < 65
65 < 57

Result:

true
false

input1 > input2

Check whether the value of input1 is greater than input2.

Function:

input1 > input2

Data Type: boolean

Example:

52 > 43
43 > 52

Result:

true
false

input1 <= input2

Check whether the value of input1 is less than or equal to input2.

Function:

input1 <= input2

Data Type: boolean

Example:

18 <= 19
19 <= 18

Result:

true
false

input1 >= input2

Check whether the value of input1 is greater than or equal to input2.

Function:

input1 >= input2

Data Type: boolean

Example:

74 >= 23
23 >= 74

Result:

true
false

is_null(input)

Determine whether the input is null. The input can be any value.

Function:

is_null(input)

Data Type: boolean

Example:

is_null(null)
is_null(6)

Result:

true
false

anything in all_values

Check whether the value <anything> is found in the collection all_values.

Function:

<anything> in all_values

Data Type: boolean

Example:

1 in ["1","2","3","4"]
0 in ["1","2","3","4"]

Result:

true
false

anything == all_values

Check whether two collections contain the same values in the same order.

Function:

<anything> == all_values

Data Type: boolean

Example:

["1", "2", "3", "4"] == ["1", "2", "3", "4"]
["0"] == ["1", "2", "3", "4"]

Result:

true
false