Operators from the condition-level operator menu follow order precedence. That is, they follow a set of rules that indicate the proper order in which conditions should be evaluated.
In common scripting languages, such as JavaScript, "and" has a higher precedence than "or." So, "and" operations are performed before "or" operations, and conditions joined by "and" also get grouped by adding parentheses around them.
This can be very complicated and confusing, so let’s look at an example.
Let’s assume that we have three questions (Occupation, Salary, and Location) and we want to configure a skip that executes when all criteria are met:
- Occupation is Designer
- Salary is $80K-$99K
- Location is Utah
To configure this, we need to create 3 conditions:
- In the first condition, we reference the Occupation question, use the includes any operator, and select "Designer" in the input/value field.
- Next, we add a second condition by clicking the + Add condition button and choose the And option from the condition-level operator menu. Remember, doing this wraps parenthesis around condition 1 and condition 2.
Select the Salary question for the data source, includes any operator, and the "80-89K" and "90-99K" options from the input/value menu. Remember here that because we selected multiple inputs/values these inputs are also wrapped in parentheses inside the condition-level parentheses.
Translated to code, this is what we have so far:
If (Occupation = "Designer" AND (Salary = "80-89K" OR "90-99K"))
- The final piece for this condition is the location. We add another condition, set the condition-level operator to And, data source to location, operator to includes any, and input/value to "Utah".
The whole statement should look like this:
Now because of how order precedence works with multiple And operators, condition 3 (the location condition) is appended to the end of the previous conditions, inside the condition-level parentheses.
So, our completed logic statement would look like this:
If (Occupation = "Designer" AND (Salary = "80-89K" OR "90-99K") AND Location = "Utah")
You can see how the And operations are always grouped, separated by Or operations (if there are any). To illustrate how the Or operator interacts within the logic let’s continue with our example.
Let’s now say that in addition to the demographic we already configured (a designer, $80K-$99K salary, in Utah), we want to add a second demographic to be considered for the skip. We also want to skip if there is a designer making $100K-$120K in California.
To do this, we add another condition (condition 4) to the skip logic statement we have been working with. This time we set the condition-level operator to Or. After that, we follow the same process as before, creating two more conditions but changing the salary range from 80-99K to 100-120K and the location to California.
The skip logic element would look like this:
And the conversion to logic would look like this:
If (Occupation = "Designer" AND (Salary = "80-89k" OR "90-99k") AND Location = "Utah") OR (Occupation = "Designer" AND (Salary = "100-109k" OR "110-119k") AND Location = "California")
The key thing to note here is that the Or operator is the separator between And operations (which get combined).