Operators

Operators are reserved characters (and combinations of adjacent characters) and can be referenced individually by their respective symbol.

Expressions are formed by combining operators with variables, constants, or functions. When an expression is encountered as part of a BASIC program statement, it is evaluated by performing the operations specified by each of the operators on the adjacent operands.

Each operator has a precedence rating and, in any given expression, the highest precedence operation is performed first. 0 is the highest precedence and 8 is the lowest. If there are two or more operators with the same precedence or if an operator displays more than once, the leftmost operation is performed first. Precedence of the operators is as follows:

Operator Operation Precedence
( ) Express evaluation 0 - highest
[ ] Substring extraction 0
^ ** Exponent 1
- Unary minus 2
* Multiplication 3
/ Division 3
+ Addition 4
- Subtraction 4
expr Format string 5
cat (:) Concatenate 6
= < > # <> >< <= >= Relational operators 7
match Pattern matching 7
and & or ! Logical operators 8 - lowest

Parentheses can be used anywhere to clarify evaluation, even if they do not change the order. An expression enclosed in parentheses as a whole has highest precedence and is evaluated first. Within the parentheses, the rules of precedence apply.

The function associated with the *=, +=, -=, /= assignment operators occurs after all left side operations and before the assignment.

See the individual entries for each operator and the entries logical operators, operators, match relational operator, precedence, relational operators, and special characters.