PDIM 104 Lecture03 - Variables
PDIM 104 Lecture03 - Variables
intX = 1 intY = 2
intResult = intX + intY
strOutput = intX & “ + “ & intY & “ = “ & intResult “1 + 2 = 3”
Often need to change the value in a variable and
assign the result back to that variable
For example: var = var – 5
Subtracts 5 from the value stored in var
Operator Usage Equivalent to Effect
+= x += 2 x=x+2 Add to
-= x -= 5 x=x–5 Subtract from
*= x *= 10x = x * 10 Multiply by
/= x /= y x=x/y Divide by
\= x \= y x=x\y Int Divide by
&= x &= “.” x = x & “.” Concatenate
Operator precedence tells us the order in which
operations are performed
From highest to lowest precedence:
Exponentiation (^)
Multiplicative (* and /)
Integer Division (\)
Modulus (MOD)
Additive (+ and -)
Parentheses override the order of precedence
Where precedence is the same, operations
occur from left to right
Parenthesis
Exponential
Multiplication / Division
Integer Division
MOD
Addition / Subtraction
String Concatenation
Relational Operators (< , > , >= , <= , <>)
Logical Operators (AND, OR, NOT)
6 * 2 ^ 3 + 4 / 2 = 50
7 *4/2–6=8
5 * (4 + 3) – 15 Mod 2 = 34
intX = 10
intY = 5
intResultA = intX + intY * 5 'iResultA is 35
iResultB = (intX + intY) * 5 'iResultB is 75
dResultA = intX - intY * 5 'dResultA is -15
dResultB = (intX - intY) * 5 'dResultB is 25
Homework
Please visit the LMS for this weeks assignment