This is the reference for the KTurtle's Logo. In this chapter we first briefly touch all the different instruction types. Then the commands are explained one by one. Then containers, math, questions and execution controllers are explained. At last you are shown how to create you own commands with learn.
As in any language, LOGO has different types of words and symbols. Here the differences between the types are briefly explained.
Using commands you tell the turtle or KTurtle to do something. Some commands need input, some give output.
# forward is a command that needs input, in this case the number 100: forward 100
For a detailed overview of all commands that KTurtle supports go here.
Most likely you already know quite a bit about numbers. The way numbers are used in KTurtle is not much different from spoken language, or math.
We have the so called natural numbers: 0
, 1
, 2
, 3
, 4
, 5
, etc. The negative numbers: -1
, -2
, -3
, etc. And the numbers with decimals, or dot-numbers, for example: 0.1
, 3.14
, 33.3333
, -5.05
, -1.0
.
Numbers can be used in mathematical calculations and questions. They can also be put in containers.
Numbers are highlighted with blue in the code editor.
First an example:
print "Hello, I'm a string."In this example
print
is a command where "Hello, I'm a string."
is a string. Strings start and end with the "
mark, by these marks KTurtle knows it is a string.Strings can be put in containers. Yet they cannot be used in mathematical calculations and questions.
Strings are highlighted with dark red in the code editor.
When using the Logo programming language you create new things. If you write a program you will often need containers and in some cases you need learn to create new commands. When making a container or a new command with learn you will have to specify a name.
You can choose any name, as long as it does not already have a meaning. For instance you cannot name a container forward, since that name is already used for a command, and thus has a meaning.
# here forward is used as a container, but it already has a meaning # so this will produce an error: forward = 20 # this works: forward 20Names can contain only letters, numbers and underscores (_). Yet they have to start with a letter.
Please read the documentation on containers and the learn command for a better explanation and more examples.
Assignment are done with the =
symbol. In programming languages it is better to read the single =
not as 'equals' but as 'becomes'. The word 'equals' is more appropriate for the ==
which is a question.
Assignments are generally use for two reasons, (1) to add content containers, and (2) to modify the content of a container. For example:
x = 10 # the container x now contains the number 10 W = "My age is: " # the container W now contains the string "My age is: " # this prints the content of the containers 'W' and 'x' on the canvas print W + x
For more examples see the section that explains containers.
KTurtle supports all basic math symbols: add (+
), substract (-
), multiply (*
), divide (/
) and the brackets (
and )
.
For a complete explanation and more examples see the math section.
We can ask simple questions on which the answer will be 'true' or 'false'.
Using questions is extensively explained in the questions section.
Questions can be glued together with so called 'question glue'. The glue words are and
, or
, and a special glue-word: not
.
Using question-glue is explained in the Question Glue section.
Comments are lines that start with a #
. For example:
# this is a comment! print "this is not a comment" # the previous line is not a comment, but the next line is: # print "this is not a comment"We can add comments to the code for ourselves or for someone else to read. Comments are used for: (1) adding a small description to the program, (2) explaining how a piece of code works if it is a bit cryptic, and (3) to 'comment-out' lines of code that should be (temporarily) ignored (see the last line of the example).
Commented lines are highlighted with dark yellow in the code editor.
Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team