Operators

Cherri supports arithmetic and assignment operators on numeric values and variables.

Table of contents

  1. Arithmetic
  2. Assignment
    1. Array append
  3. Conditional and logical operators

Arithmetic

Arithmetic expressions operate on numbers and produce a result that can be stored in a constant or variable.

Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus (remainder)
const sum = 10 + 5
const difference = 10 - 5
const product = 10 * 5
const quotient = 10 / 5
const remainder = 10 % 3

Both operands can be variables:

@a = 10
@b = 3
const result = @a % @b

Assignment

Assignment operators modify a variable in place.

Operator Description
= Set value
+= Add to
-= Subtract from
*= Multiply by
/= Divide by
@n = 10
@n += 5
@n -= 2
@n *= 3
@n /= 2

Array append

When used on an array variable, += appends an item rather than performing numeric addition.

@items: array
@items += "first"
@items += "second"

Conditional and logical operators

Conditional operators (==, !=, contains, >, etc.) and logical operators (&&, ||) are used in if statements and are covered in Control Flow.


Copyright ©. Distributed under the GPL-2.0 License. Siri Shortcuts and Mac are registered trademarks of Apple Inc. Apple is not involved in this project in any way. Do not contact Apple Support unless you are having an issue with the Shortcuts app itself.