What is an Operator

An operator is a symbol to express an operation (function).

Unary Operator

An unary operation has one operator and one operand.

Sign Operator

In Small Basic, sign operator is only minus.  So, plus operator becomes error such as x = +1.

• - minus

Binary Operators

An binary operation has one operator and two operands.

Substitution Operator

Substitution statements in Small Basic give value into variables or properties with substitution operator.

• = (substitute)

Arithmetic Operators

There are for arithmetic operators in Small Basic.

• - (subtract)
• * (multiple)
• / (divide)

Comparison Operators

There are six comparison operators in Small Basic.  These operators can be used in conditions for If, While and For statements.  Only equal (=) operator can compare two texts or two numbers.  Other operators are for numbers only.

• = (equal to)
• < (less than)
• > (greater than)
• <= (less than or equal to)
• >= (greater than or equal to)
• <> (not equal to)

Logical Operators

There are two logical (Boolean) operators in Small Basic.  Logical operators can be used in conditions for If and While statements.

• And
• Or

Text Operator

There is one text operator in Small Basic.  This operator uses same character (+) for add operator.  If one of two operands is not number,  the operator is treated as concatenate.

• + (concatenate)

Sample Code

' Sample Code for Operators

' Unary Operator ----------
' Sign Operator
a = 3
TextWindow.Write("-a = ")
TextWindow.WriteLine(-a)      ' - (minus)

' Binary Operators ----------
' Substitution Operator
b = a                         ' = (substitute)
TextWindow.Write("b = ")
TextWindow.WriteLine(b)

' Arithmetic Operators
TextWindow.Write("a + b = ")
TextWindow.WriteLine(a + b)   ' + (add)
TextWindow.Write("a - b = ")
TextWindow.WriteLine(a - b)   ' - (subtract)
TextWindow.Write("a * b = ")
TextWindow.WriteLine(a * b)   ' * (multiple)
TextWindow.Write("a / b = ")
TextWindow.WriteLine(a / b)   ' / (divide)

' Comparison Operations
If a = b Then                 ' = (equal to)
TextWindow.WriteLine("a = b")
EndIf
If a < b Then                 ' < (less than)
TextWindow.WriteLine("a < b")
EndIf
If a > b Then                 ' > (greater than)
TextWindow.WriteLine("a > b")
EndIf
If a <= b Then                ' <= (less than or equal to)
TextWindow.WriteLine("a <= b")
EndIf
If a >= b Then                ' >= (greater than or equal to)
TextWindow.WriteLine("a >= b")
EndIf
If a <> b Then                ' <> (not equal to)
TextWindow.WriteLine("a <> b")
EndIf

' Logical Operators
If (5 <= a) And (a <= 10) Then  ' And
TextWindow.WriteLine("(5 <= a) And (a <= 10)")
EndIf
If (a < 5) Or (10 < a) Then     ' Or
TextWindow.WriteLine("(a < 5) Or (10 < a)")
EndIf

' Text Operator
TextWindow.WriteLine(a + " ^ 2 = " + Math.Power(a, 2))  ' + (concatenate)