Expressions and Operators. Commodore 4.0
Διαφήμιση
Διαφήμιση
1.8 EXPRESSIONS AND OPERATORS
An expression may be simply a string or numeric constant, or a variable, or it may combine constants and variables with operators to produce a single value.
Operators perform mathematical or logical operations on values. The operators provided by BASIC may be divided into four categories:
I. Arithmetic
2. Relational
3. Logical
4. Functional
1.8.1 Arithmetic Operators
[lie arithmetic operators, in order of preference, are:
Operator
T
*,J
+.-
Operation
Exponentiation
Negation
Multiplication, Floating
Point Division
Addition. Subtraction
Sample
X|
- X
X*Y
X/Y
X+Y
X-Y
To change the order in which the operations are performed, use parentheses. Operations within parentheses are performed first. Inside parentheses, the usual order of operations is maintained.
Maximum nesting of parentheses for binary arithmetic is 10 levels.
Here are some sample algebraic expressions and their BASIC counterparts.
ALGEBRAIC EXPRESSION
X+2Y
X - Y
Z
XY
Z
X+Y
Z
(X
2
)Y
XY
Z
X(-Y)
BASIC EXPRESSION
X+Y*2
X-Y/Z
X*Y/Z
(X+Y)/Z
(X|2)TY
XT(YTZ)
X*(-Y) Two consecutive operators must be separated by parentheses.
15
Λήψη
Διαφήμιση