b) Instructions returning a value
************************************
Some instructions return a value. For example, the mathematical expression "squareroot" returns a number. For example :

hehe = squareroot(4);

The variable "hehe" now contains the value 2.


c) Control Instructions
*************************
The control instructions are not usually written with parenthesis, if they dont require parameters.

- repeat


This instruction requires that what is to be repeated is placed within braces
{}. The parameter is the number of times the instruction is to be repeated. For example :

hehe = 30;

repeat(20)
{
forward(hehe);
}

is equivalent to:

forward(600);

Note that such an expression cannot be written in the console, because it will give an error message. You will have to write it up in a "New function..." window and give it a name. There is no semi-colon after the braces or after the instruction "repeat".

You can leave the execution of the instructions within the braces with the instruction"break", For example:

repeat(20)
{
forward(10);
break;
}

is equivalent to :

forward(10);

The instruction "break" exits the loop. This instruction is useful when there are many iteration and selection instructions. There is no parenthesis after the instruction "break".

- the"while" instruction

This instruction allows you to repeat an instruction as long as a condition remains true. For example:

hehe = 20;

while (hehe > 0)
{
forward(30);
hehe = hehe -1;
}

is equivalent to :

forward(600);

Within the braces, one can exit the loop immediately with the "break" instruction. Here again, the elaborate version must be typed in the "New function..." window.

The condition "hehe > 0" is evaluated at every iteration.

The allowed conditions are :



Larger than >
Smaller than <
Equal ==
Different from !=
Larger or equal to >=
Smaller or equal to <=

One can compare numbers with numbers and characters with characters

-the"if" instruction

This instruction allows you to make a selection. There is a second instruction, "else ", which is optional. It is similar to the while instruction. For example :

hehe = 12;
if (hehe == 12)
{
forward(10);
}

is equivalent to :

forward(10);

We can also write:

hehe = 12;
if (hehe != 12)
{
forward(10);
}
else
{
forward(20);
}

This is equivalent to :

forward(20);

There is no semi-colon after the braces or after the instructions " if " and " else ".