a = 2 + 3
if not a > 5 ' ... end if
a = 2 + "3" ' a = 5, because "3" is converted to 3 b = 2 + "three" ' b = 2, because "three" is not a number and it is converted to 0
Text = "Value is: " & 3 ' Text = "Value is: 3", because 3 is converted to "3"
if a < 10 ' ... end if
if a < 10 and a > 5 ' ... end if
Arithmetic operators in Toy Basic:
| Operator | Example | Description |
|---|---|---|
| + | a = b + 6 | Addition - adds two numbers together |
| - | a = b - 6 | Subtraction - subtracts the second number from the first one |
| * | a = b * 6 | Multiplication - multiplies two numbers together |
| / | a = b / 6 | Division - divides the first number by the second one |
| % | a = b % 6 | Modulus - returns the remainder of dividing the first number by the second one |
| ^ | a = b ^ 6 | Exponentiation - raises the value to the first number to the power of the second one |
| Operator | Example | Description |
|---|---|---|
| & | s = "Hello " & name | Concatenation - join two strings into a single string |
| Operator | Example | Description |
|---|---|---|
| = | if a + 1 = 5 | Equality - Is the value of the first expression equal to the value of the second? You can compare numbers and strings, but if you compare a string to a number, number is converted to strings |
| <> | if a + 1 <> 5 | Inquality - Is the value of the first expression unequal to the value of the second? You can compare only numbers, strings are always converted to numbers for comparison. |
| < | if a + 1 < 5 | Less than - Is the value of the first expression less than the value of the second? You can compare only numbers, strings are always converted to numbers for comparison. |
| > | if a + 1 > 5 | Greater than- Is the value of the first expression greater than the value of the second? You can compare only numbers, strings are always converted to numbers for comparison. |
| <= | if a + 1 <= 5 | Less than or equal to - Is the value of the first expression less than or equal to the value of the second? You can compare only numbers, strings are always converted to numbers for comparison. |
| >= | if a + 1 >= 5 | Greater than or equal to - Is the value of the first expression greater than or equal to the value of the second? You can compare only numbers, strings are always converted to numbers for comparison. |
| Operator | Example | Description |
|---|---|---|
| AND | if a > 5 and a < 10 | Condition is met, when both expressions are true |
| OR | if a > 5 or a < 10 | Condition is met, when at least one expression is true |
| NOT | if not a > 5 | Remember, NOT is an unary operator. Condition is met, expression is NOT true |
a = 2 * (3 + 4) ' a = 14
a = 2 * 3 ^ 2 ' a = 18
a = 2 + 4 / 2 ' a = 4
if 3 + 4 < 1 + 7 ' condition is true
if not 2 > 10 ' condition is true
if not 2 > 10 and 3 < 5' condition is true
if not 2 < 10 or 3 < 5' condition is true
See also: