execute
{
}
As the prgrams get bigger, indentation helps the human
reader to understand what is going on,
as shown below,
but it does not matter to the compiler,
For example, this program
execute
{
new basic_bot karel;
tell karel:
{
TurnLeft;
Move 1;
}
}
and this program
execute { new basic_bot karel; tell karel: {TurnLeft; Move 1; } }
are exactly the same to the compiler, but which would you rather read,
especially if the program got any larger?
The above example also showed a preview of what can be placed inside an execution block. For now, it is sufficient to say the new statement creates a new robot of a specific type and gives it a name. In the above example, the type of robot is a basic_bot and the name given to it is karel. Later on we'll discuss how to create additional types of robots, but basic_bot is the only robot type available to us for now.
The tell statement lists one or more instructions that should be sent or told to the specified robot. In the above case, we've told the robot karel to do two things: TurnLeft and Move 1. Just what these and other instructions do are discussed below.
The following sample shows the above instructions that might be used to tell a robot (which in this case we name karel) to pick up a beeper next to it (assuming there is at least one), move it to the square in front of karel, return back to the original square, and turn off.
execute
{
new basic_bot karel;
tell karel:
{
PickBeeper;
Move 1;
PutBeeper;
TurnLeft;
TurnLeft;
Move 1;
TurnLeft;
TurnLeft;
TurnOff;
}
}
You can also go:
Created on 16 June 1995
Last revised 20 August 1996