Operators

BambooBasic supports various operators for arithmetic, comparison, logical operations, and bitwise manipulation.



Arithmetic Operators

Used for mathematical calculations:

+   Addition         x = 5 + 3      ; Result: 8
-   Subtraction      x = 5 - 3      ; Result: 2
*   Multiplication   x = 5 * 3      ; Result: 15
/   Division         x = 10 / 2     ; Result: 5
Mod Modulo          x = 10 Mod 3   ; Result: 1 (remainder)

Power operations: Use BBR_Pow(base, exponent) - Example: BBR_Pow(2, 3) returns 8



Comparison Operators

Used to compare values (returns True or False):

=   Equal to              If x = 5 Then ...
<>  Not equal to          If x <> 5 Then ...
<   Less than             If x < 5 Then ...
>   Greater than          If x > 5 Then ...
<=  Less than or equal    If x <= 5 Then ...
>=  Greater than or equal If x >= 5 Then ...


Logical Operators

Used to combine boolean expressions:

And  Logical AND    If x > 0 And x < 10 Then ...
Or   Logical OR     If x = 0 Or x = 10 Then ...
Not  Logical NOT    If Not gameOver Then ...

Examples:

; AND - Both conditions must be true
If age >= 18 And hasLicense = True Then
    Print "Can drive"
EndIf

; OR - At least one condition must be true
If score = 100 Or lives = 0 Then
    Print "Game Over"
EndIf

; NOT - Inverts the boolean value
If Not gameStarted Then
    Print "Press Start"
EndIf


Bitwise Operators

Used for bit-level operations on integers:

BitAnd  Bitwise AND     result = a BitAnd b
BitOr   Bitwise OR      result = a BitOr b
&       Bitwise OR      result = a & b      ; Same as BitOr
BitXor  Bitwise XOR     result = a BitXor b
BitNot  Bitwise NOT     result = BitNot a
Shl     Shift Left      result = a Shl 2    ; Multiply by 4
Shr     Shift Right     result = a Shr 2    ; Divide by 4

Note: The & symbol is used for both string concatenation (with strings) and bitwise OR (with integers).

Common Uses:

; Flags using bitwise OR
Const FLAG_VISIBLE:Int = 1
Const FLAG_SOLID:Int = 2
Const FLAG_ANIMATED:Int = 4

; Using & or BitOr (both work the same)
Local flags:Int = FLAG_VISIBLE & FLAG_SOLID
; or
Local flags2:Int = FLAG_VISIBLE BitOr FLAG_SOLID

; Check flag using bitwise AND
If (flags BitAnd FLAG_VISIBLE) <> 0 Then
    Print "Object is visible"
EndIf

Want to learn more? See the Complete Bitwise Operations Tutorial for in-depth coverage of binary, hexadecimal, and practical applications.



Assignment Operator
=   Assignment          x = 5

To modify a variable, use the full expression:

x = x + 3    ; Add to x
x = x - 3    ; Subtract from x
x = x * 3    ; Multiply x
x = x / 3    ; Divide x


String Concatenation

Use & to join strings together:

Local firstName$ = "John"
Local lastName$ = "Smith"
Local fullName$ = firstName & " " & lastName
Print fullName  ; Output: John Smith


Operator Precedence

Operators are evaluated in this order (highest to lowest):

1. * / Mod          (Multiplication, Division, Modulo)
2. + -              (Addition, Subtraction)
3. Shl Shr          (Bit Shifts)
4. < > <= >= = <>   (Comparison)
5. Not BitNot       (Logical/Bitwise NOT)
6. And BitAnd       (Logical/Bitwise AND)
7. Or BitOr BitXor  (Logical/Bitwise OR, XOR)

Use parentheses to override precedence:

result = (5 + 3) * 2    ; Result: 16
result = 5 + 3 * 2      ; Result: 11


Examples

BambooBasic © 2026 Michael Denathorn