The title of this section might sound very difficult, yet it is not as difficult as it sound.

These are the basic math symbols known as: add (** +**), subtract (

**), multiply (**

`-`

**), divide (**

`*`

**) and power (**

`/`

**).**

`^`

Here a small example of the mathematical operators you can use in TurtleScript:

$add = 1 + 1 $subtract = 20 - 5 $multiply = 15 * 2 $divide = 30 / 30 $power = 2 ^ 2

The values resulting from the mathematical operations get assigned to various variables. Using the inspector you can see the values.

If you just want a simple calculation to be done you can do something like this:

print 2010-12

Now an example with parentheses:

print ( ( 20 - 5 ) * 2 / 30 ) + 1

The expressions inside parentheses will be calculated first. In this example, 20-5 will be calculated, then multiplied by 2, divided by 30, and then 1 is added (giving 2). Parentheses can also be used in other cases.

KTurtle also has more advanced mathematical features in the form of commands. Have a look at the following commands but be aware that it concerns advanced operations: round, random, sqrt , pi, sin, cos, tan, arcsin, arccos, arctan.

Where mathematical operators are mainly for numbers, boolean operators are for boolean values (** true** and

**). There are only three boolean operators, namely:**

`false`

**,**

`and`

**, and**

`or`

**. The following piece of TurtleScript shows how to use them:**

`not`

$and_1_1 = true and true # -> true $and_1_0 = true and false # -> false $and_0_1 = false and true # -> false $and_0_0 = false and false # -> false $or_1_1 = true or true # -> true $or_1_0 = true or false # -> true $or_0_1 = false or true # -> true $or_0_0 = false or false # -> false $not_1 = not true # -> false $not_0 = not false # -> true

Using the inspector you can see the values, yet we also supply these results as little comments at the end of the lines. ** and** evaluates

**only if both sides are**

`true`

**.**

`true`

**evaluates**

`or`

**if either side is**

`true`

**. And**

`true`

**turns a**

`not`

**into**

`true`

**and a**

`false`

**into**

`false`

**.**

`true`

Boolean operators are *highlighted* with pink.

Consider the following example with ** and**:

$a = 1 $b = 5 if (($a < 10) and ($b == 5)) and ($a < $b) { print "hello" }

In this piece of TurtleScript the result of three comparing operators are merged using ** and** operators. This means that all three have to evaluate “true” in order for the “hello” to be printed.

An example with ** or**:

$n = 1 if ($n < 10) or ($n == 2) { print "hello" }

In this piece of TurtleScript the left side of the ** or** is evaluating to “true”, the right side to “false”. Since one of the two sides of the

**operator is “true”, the**

`or`

**operator evaluates “true”. That means “hello” gets printed.**

`or`

And finally an example with ** not** which changes “true” into “false” and “false” into “true”. Have a look:

$n = 1 if not ($n == 3) { print "hello" } else { print "not hello ;-)" }

Consider this simple comparison:

$answer = 10 > 3

Here ** 10** is compared to

**with the “greater than” operator. The result of this comparison, the boolean value**

`3`

**is stored in the variable**

`true`

**.**

`$answer`

All numbers and variables (that contain numbers) can be compared to each other with comparing operators.

Here are all possible comparing operators:

**Table 4.1. Types of questions**

`$A == $B` | equals | answer is “true” if equals `$A` `$B` |

`$A != $B` | not-equals | answer is “true” if does not equal `$A` `$B` |

`$A > $B` | greater than | answer is “true” if is greater than `$A` `$B` |

`$A < $B` | smaller than | answer is “true” if is smaller than `$A` `$B` |

`$A >= $B` | greater than or equals | answer is “true” if is greater than or equals `$A` `$B` |

`$A <= $B` | smaller than or equals | answer is “true” if is smaller than or equals `$A` `$B` |

Please note that ** $A** and

**have to be numbers or variables that contain numbers.**

`$B`