Original Author Paul Laughton, 2011
Page 53
De Re BASIC!
Numeric Operators <noperator>
The numeric operators are listed by precedence. Higher precedence operators are executed before
lower precedence operators. Precedence can be changed by using parentheses.
1.
Unary +, Unary ­
2.
Exponent ^
3.
Multiply *, Divide /
4.
Add +, Subtract ­
Note that the comma (',') is not an operator in BASIC!. It is sometimes uses as a separator between
expressions; for example, see the PRINT command.
Numeric Expression Examples
a
a*b + 4/d ­ 2*(d^2)
a + b + d + RND()
b + CEIL(d/25) + 5
Pre- and Post-Increment Operators
++x
Increments the value of x by 1 before the x value is used
--y
Decrements the value of y by 1 before the y value is used
x++
Increments the value of x by 1 after the x value is used
y--
Decrements the value of y by 1 after the y value is used
a = 5
% creates the variable a and sets it to 5
PRINT --a
% sets a to 4 and prints 4
PRINT a--
% prints 4 and sets a to 3
These operations work only on numeric variables. Their action is performed as part of evaluating the
variable, so they do not follow normal precedence rules.
Using these operators on a variable makes the variable unavailable for other operations that require a
variable. For example, you cannot pass a variable by reference (see User-Defined functions) if you pre-
or post-increment or -decrement it, because you cannot pass an expression by reference. An exception
is made to allow implicit assignment (actual or implied LET).
String Expression <sexp>
A string expression consists of one or more string variables or string constants separated by '+'
operators. The definition can be stated more completely using this standard formal notation:
<sexp> := {<string variable>|<string constant>} {
+ <sexp>}
There is only one string operator: +. This is the concatenation operator. It is used to join two strings:
PRINT "abc" + "def" % prints abcdef