Logical and Comparison operators

In CoyoteScript, just like in most other script and programming languages, logical operators and comparison operators are used to create expressions, which are used to check whether or not certain conditions are met. If a condition is met, we refer to the result as “true”, and if it is not met, we refer to it as “false”.

 

Comparison Operators

Comparison operators are used to describe what relationship between 2 values is required for the condition to be met. In CoyoteScript, these are:

  1. “==” The values on either side of the operator have to be identical.
  2. “!=” The values on either side of the operator must be different from eachother.
  3. “>” The value on the left of the operator has to be greater than the value on the right. This is only applicable for numerical values.
  4. “>=” The value on the left has to be greater than or equal to the value on the right. This is only applicable for numerical values.
  5.  “<” The value on the left has to be smaller than the value on the right. This is only applicable for numerical values.
  6. “<=” The value on the left has to be smaller than or equal to the value on the right. This is only applicable for numerical values.

For example:

  1. “hello == hey” would resolve to “false”.
  2. “hello != hey” would resolve to “true”.
  3. “8 > 3” would resolve to “true”.
  4. “5 <= 4” would resolve to “false”.

Logical Operators

Logical operators are used to resolve multiple conditions into a single expression. In CoyoteScript, these are:

  1. “&&” The conditions on either side of the operator both need to resolve to “true” for the combined result to be “true”.
  2.  “||” Only one of the conditions on either side has to be “true” for the combined result to be “true”.

For example:

  1. “hello == hello && 7 > 2” would resolve to “true” as both conditions would resolve to “true”.
  2. “hello = hey || 5 <= 9” would resolve to “true” because one of the conditions would resolve to “true”.

 

The order in which the conditions in the expression are resolved can be controlled with parenthesis. Conditions inside parenthesis will be resolved first, and multiple parenthesis can be nested inside another, just like in mathematical operations.

For example:

“hello != hi && (7 < 2 || 8 > 4)” would resolve to “true”.