Mathematical
Name |
Syntax example |
Comments |
---|---|---|
Multiplication |
|
|
Division |
|
|
Remainder |
|
Often called mod or modulus |
Addition |
|
|
Subtraction |
|
|
Exponent |
|
Do not confuse this with Bitwise Xor ^ |
Bitshift Right |
|
|
Bitshift Left |
|
|
Bitwise And |
|
|
Bitwise Or |
|
|
Bitwise Xor |
|
The mathematical operators can also be used in the syntax a <operator>= b
, for example, a += b
.
This is merely a shortcut for a = a <operator> b
, or in our example a = a + b
.
Relational and Logical
Name |
Syntax Example |
Comments |
---|---|---|
Less Than |
|
|
Greater Than |
|
|
Less Than or Equal To |
|
|
Greater Than or Equal To |
|
|
Equality |
|
|
Inequality |
|
|
Logical And |
|
Only use when |
Logical Or |
|
Only use when |
Logical Not |
|
Only use when |
Types
Name |
Syntax Example |
Comments |
---|---|---|
Typecast |
|
|
Typecast |
|
|
Type Equality/Compatibility |
|
|
Type Retrieval |
|
|
Type Retrieval |
|
Primary
Name |
Syntax Example |
Comments |
---|---|---|
Member |
|
Classes are described in
Part 08 - Classes
|
Function Call |
|
Functions are described in
Part 07 - Functions
|
Post Increment |
|
|
Post Decrement |
|
|
Constructor Call |
|
Classes are described in Part 08 - Classes |
Unary
Name |
Syntax Example |
Comments |
---|---|---|
Negative Value |
|
|
Pre Increment |
|
See [Difference between Pre and Post Increment/Decrement](https://github.com/bamboo/boo/wiki/Boo-Primer:-%5BPart-06%5D-Operators) |
Pre Decrement |
|
See [Difference between Pre and Post Increment/Decrement](https://github.com/bamboo/boo/wiki/Boo-Primer:-%5BPart-06%5D-Operators) |
Grouping |
|
Difference between Pre and Post Increment/Decrement
When writing inline code, Pre Increment/Decrement (+i/-i) commit the action, then return its new value, whereas Post Increment/Decrement (i+/i-) return the current value, then commit the change.
preincrement vs. postincrement
num = 0
for i in range(5):
print num++
print '---'
num = 0
for i in range(5):
print ++num
// Output:
// 0
// 1
// 2
// 3
// 4
// ---
// 1
// 2
// 3
// 4
// 5
Hint
To make your code more readable, avoid using the incrementors and decrementors. Instead, use i += 1 and i -= 1.
Exercises
- Put your hands on a wall, move your left foot back about 3 feet, move the right foot back 2 feet.