-
Notifications
You must be signed in to change notification settings - Fork 148
Boo Primer: [Part 06] Operators
Added by Cameron Kenneth Knight
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
.
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 |
Name |
Syntax Example |
Comments |
---|---|---|
Typecast |
|
|
Typecast |
|
|
Type Equality/Compatibility |
|
|
Type Retrieval |
|
|
Type Retrieval |
|
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 |
Name |
Syntax Example |
Comments |
---|---|---|
Negative Value |
|
|
Pre Increment |
|
See [Difference between Pre and Post Increment/Decrement](Boo-Primer:-%5BPart-06%5D-Operators) |
Pre Decrement |
|
See [Difference between Pre and Post Increment/Decrement](Boo-Primer:-%5BPart-06%5D-Operators) |
Grouping |
|
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.
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
Recommendation: To make your code more readable, avoid using the incrementors and decrementors. Instead, use i += 1 and i -= 1.
- Put your hands on a wall, move your left foot back about 3 feet, move the right foot back 2 feet.
Go on to Part 07 - Functions
Back to: Home | Boo Primer