1 <!--Dear translator: please NEVER translate the id or anything inside the tags as they are needed in english by the application
2 Thanks a lot in advance.-->
3 <chapter id="reference">
4 <title>&kturtle;'s &logo; Programming Reference</title>
5 <para>This is the reference for the &kturtle;'s &logo;. In this chapter we first briefly touch all the <link linkend="different-instructions">different instruction types</link>. Then the <link linkend="commands">commands</link> are explained one by one. Then <link linkend="containers">containers</link>, <link linkend="math">math</link>, <link linkend="questions">questions</link> and <link linkend="controlling-execution">execution controllers</link> are explained. At last you are shown how to create you own commands with <link linkend="learn">learn</link>.</para>
7 <sect1 id="different-instructions">
8 <title>Different Instruction Types</title>
9 <para>As in any language, LOGO has different types of words and symbols. Here the differences between the types are briefly explained.</para>
12 <title>Commands</title>
13 <para>Using commands you tell the turtle or &kturtle; to do something. Some commands need input, some give output.
15 # forward is a command that needs input, in this case the number 100:
19 <para>For a detailed overview of all commands that &kturtle; supports go <link linkend="commands">here</link>.</para>
23 <title>Numbers</title>
24 <para>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. </para>
25 <para>We have the so called natural numbers: <userinput>0</userinput>, <userinput>1</userinput>, <userinput>2</userinput>, <userinput>3</userinput>, <userinput>4</userinput>, <userinput>5</userinput>, etc. The negative numbers: <userinput>-1</userinput>, <userinput>-2</userinput>, <userinput>-3</userinput>, etc. And the numbers with decimals, or dot-numbers, for example: <userinput>0.1</userinput>, <userinput>3.14</userinput>, <userinput>33.3333</userinput>, <userinput>-5.05</userinput>, <userinput>-1.0</userinput>.
27 <para>Numbers can be used in <link linkend="math">mathematical calculations</link> and <link linkend="questions">questions</link>. They can also be put in <link linkend="containers">containers</link>.</para>
28 <para>Numbers are <glossterm>highlighted</glossterm> with blue in the <link linkend="the-code-editor">code editor</link>.</para>
32 <title>Strings</title>
33 <para>First an example:
35 print "Hello, I'm a string."
37 In this example <userinput>print</userinput> is a command where <userinput>"Hello, I'm a string."</userinput> is a string. Strings start and end with the <userinput>"</userinput> mark, by these marks &kturtle; knows it is a string.</para>
38 <para>Strings can be put in <link linkend="containers">containers</link>. Yet they cannot be used in <link linkend="math">mathematical calculations</link> and <link linkend="questions">questions</link>.</para>
39 <para>Strings are <glossterm>highlighted</glossterm> with dark red in the <link linkend="the-code-editor">code editor</link>.</para>
45 <para>When using the &logo; programming language you create new things. If you write a program you will often need <link linkend="containers">containers</link> and in some cases you need <link linkend="learn">learn</link> to create new commands. When making a <link linkend="containers">container</link> or a new command with <link linkend="learn">learn</link> you will have to specify a name.</para>
46 <para>You can choose any name, as long as it does not already have a meaning. For instance you cannot name a container <link linkend="forward">forward</link>, since that name is already used for a command, and thus has a meaning.
48 # here forward is used as a container, but it already has a meaning
49 # so this will produce an error:
55 Names can contain only letters, numbers and underscores (_). Yet they have to start with a letter.
58 Please read the documentation on <link linkend="containers">containers</link> and the <link linkend="learn">learn</link> command for a better explanation and more examples.
62 <sect2 id="assignment">
63 <title>Assignments</title>
64 <para>Assignment are done with the <userinput>=</userinput> symbol. In programming languages it is better to read the single <userinput>=</userinput> not as 'equals' but as 'becomes'. The word 'equals' is more appropriate for the <userinput>==</userinput> which is a <link linkend="questions">question</link>.</para>
65 <para>Assignments are generally use for two reasons, (1) to add content <link linkend="containers">containers</link>, and (2) to modify the content of a container. For example:
68 # the container x now contains the number 10
70 # the container W now contains the string "My age is: "
71 # this prints the content of the containers 'W' and 'x' on the canvas
75 <para>For more examples see the section that explains <link linkend="containers">containers</link>.</para>
78 <sect2 id="math-symbols">
79 <title>Math Symbols</title>
80 <para>&kturtle; supports all basic math symbols: add (<userinput>+</userinput>), substract (<userinput>-</userinput>), multiply (<userinput>*</userinput>), divide (<userinput>/</userinput>) and the brackets <userinput>(</userinput> and <userinput>)</userinput>.</para>
81 <para>For a complete explanation and more examples see the <link linkend="math">math</link> section.</para>
85 <title>Questions</title>
86 <para>We can ask simple questions on which the answer will be 'true' or 'false'.</para>
87 <para>Using questions is extensively explained in the <link linkend="questions">questions</link> section.</para>
90 <sect2 id="questions-glue">
91 <title>Question Glue-Words</title>
92 <para>Questions can be glued together with so called 'question glue'. The glue words are <userinput>and</userinput>, <userinput>or</userinput>, and a special glue-word: <userinput>not</userinput>.</para>
93 <para>Using question-glue is explained in the <link linkend="question-glue">Question Glue</link> section.</para>
98 <title>Comments</title>
99 <para>Comments are lines that start with a <userinput>#</userinput>. For example:
102 print "this is not a comment"
103 # the previous line is not a comment, but the next line is:
104 # print "this is not a comment"
106 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).</para>
107 <para>Commented lines are <glossterm>highlighted</glossterm> with dark yellow in the <link linkend="the-code-editor">code editor</link>.</para>
113 <sect1 id="commands">
114 <title>Commands</title>
115 <para>Using commands you tell the turtle or &kturtle; to do something. Some commands need input, some give output. In this section we explain all the commands that can be used in &kturtle;. Please note that all build in commands we discuss here are <glossterm>highlighted</glossterm> with dark green in the <link linkend="the-code-editor">code editor</link>, this can help you to distinguish them.</para>
117 <sect2 id="moving-the-turtle">
118 <title>Moving the turtle</title>
119 <para>There are several commands to move the turtle over the screen.</para>
122 <title>forward (fw)</title>
126 <listitem><para><screen>forward X</screen>
127 <userinput>forward</userinput> moves the turtle forward by the amount of X pixels. When the pen is down the turtle will leave a trail. <userinput>forward</userinput> can be abbreviated to <userinput>fw</userinput></para></listitem>
131 <sect3 id="backward">
132 <title>backward (bw)</title>
135 <term>backward</term>
136 <listitem><para><screen>backward X</screen>
137 <userinput>backward</userinput> moves the turtle backward by the amount of X pixels. When the pen is down the turtle will leave a trail. <userinput>backward</userinput> can be abbreviated to <userinput>bw</userinput>.</para></listitem>
141 <sect3 id="turnleft">
142 <title>turnleft (tl)</title>
145 <term>turnleft</term>
146 <listitem><para><screen>turnleft X</screen>
147 <userinput>turnleft</userinput> commands the turtle to turn an amount of X degrees to the left. <userinput>turnleft</userinput> can be abbreviated to <userinput>tl</userinput>.</para></listitem>
151 <sect3 id="turnright">
152 <title>turnright (tr)</title>
155 <term>turnright</term>
156 <listitem><para><screen>turnright X</screen>
157 <userinput>turnright</userinput>the turtle to turn an amount of X degrees to the right. <userinput>turnright</userinput> can be abbreviated to <userinput>tr</userinput>.</para></listitem>
161 <sect3 id="direction">
162 <title>direction (dir)</title>
165 <term>direction</term>
166 <listitem><para><screen>direction X</screen>
167 <userinput>direction</userinput> set the turtle's direction to an amount of X degrees counting from zero, and thus is not relative to the turtle's previous direction. <userinput>direction</userinput> can be abbreviated to <userinput>dir</userinput>.</para></listitem>
172 <title>center</title>
176 <listitem><para><screen>center</screen>
177 <userinput>center</userinput> moves the turtle to the center on the canvas.</para></listitem>
186 <listitem><para><screen>go X,Y</screen>
187 <userinput>go</userinput> commands the turtle to go to a certain place on the canvas. This place is X <glossterm linkend="pixels">pixels</glossterm> from the left of the canvas, and Y <glossterm linkend="pixels">pixels</glossterm> form the top of the canvas. Note that using the <userinput>go</userinput> command the turtle will not draw a line.</para></listitem>
196 <listitem><para><screen>gox X</screen>
197 <userinput>gox</userinput> using this command the turtle will move to X <glossterm linkend="pixels">pixels</glossterm> from the left of the canvas whilst staying at the same height.</para></listitem>
206 <listitem><para><screen>goy Y</screen>
207 <userinput>gox</userinput> using this command the turtle will move to Y <glossterm linkend="pixels">pixels</glossterm> from the top of the canvas whilst staying at the same distance from the left border of the canvas.</para></listitem>
214 <title>The turtle has a pen</title>
215 <para>The turtle has a pen that draws a line when the turtle moves. There are a few commands to control the pen. In this section we explain these commands.</para>
217 <title>penup (pu)</title>
221 <listitem><para><screen>penup</screen>
222 <userinput>penup</userinput> lifts the pen from the canvas. When the pen is <quote>up</quote> no line will be drawn when the turtle moves. See also <userinput>pendown</userinput>. <userinput>penup</userinput> can be abbreviated to <userinput>pu</userinput>.</para></listitem>
227 <title>pendown (pd)</title>
231 <listitem><para><screen>pendown</screen>
232 <userinput>pendown</userinput> presses the pen down on the canvas. When the pen is press <quote>down</quote> on the canvas a line will be drawn when the turtle moves. See also <userinput>penup</userinput>. <userinput>pendown</userinput> can be abbreviated to <userinput>pd</userinput>.</para></listitem>
236 <sect3 id="setpenwidth">
237 <title>penwidth (pw)</title>
240 <term>penwidth</term>
241 <listitem><para><screen>penwidth X</screen>
242 <userinput>penwidth</userinput> sets the width of the pen (the line width) to an amount of X <glossterm linkend="pixels">pixels</glossterm>. <userinput>penwidth</userinput> can be abbreviated to <userinput>pw</userinput>.</para></listitem>
246 <sect3 id="setfgcolor">
247 <title>pencolor (pc)</title>
250 <term>pencolor</term>
251 <listitem><para><screen>pencolor R,G,B</screen>
252 <userinput>pencolor</userinput> sets the color of the pen. <userinput>pencolor</userinput> takes an <glossterm linkend="rgb">RGB combination</glossterm> as input. <userinput>pencolor</userinput> can be abbreviated to <userinput>pc</userinput>.</para></listitem>
259 <title>Commands to control the canvas</title>
260 <para>There are several commands to control the canvas.</para>
261 <sect3 id="resizecanvas">
262 <title>canvassize (cs)</title>
265 <term>canvassize</term>
266 <listitem><para><screen>canvassize X,Y</screen>
267 With the <userinput>canvassize</userinput> command you can set the size of the canvas. It takes X and Y as input, where X is the new canvas width in <glossterm linkend="pixels">pixels</glossterm>, and Y is the new height of the canvas in <glossterm linkend="pixels">pixels</glossterm>. <userinput>canvassize</userinput> can be abbreviated to <userinput>cs</userinput>.</para></listitem>
271 <sect3 id="setbgcolor">
272 <title>canvascolor (cc)</title>
275 <term>canvascolor</term>
276 <listitem><para><screen>canvascolor R,G,B</screen>
277 <userinput>canvascolor</userinput> set the color of the canvas. <userinput>canvascolor</userinput> takes an <glossterm linkend="rgb">RGB combination</glossterm> as input. <userinput>canvascolor</userinput> can be abbreviated to <userinput>cc</userinput>.</para></listitem>
282 <title>wrapon</title>
286 <listitem><para><screen>wrapon</screen>
287 With the <userinput>wrapon</userinput> command you can set <glossterm linkend="wrapping">wrapping</glossterm> <quote>on</quote> for the canvas. Please see the glossary if you want to know what <glossterm linkend="wrapping">wrapping</glossterm> is.</para></listitem>
292 <title>wrapoff</title>
296 <listitem><para><screen>wrapoff</screen>
297 With the <userinput>wrapoff</userinput> command you can set <glossterm linkend="wrapping">wrapping</glossterm> <quote>off</quote> for the canvas: this means the turtle can move off the canvas and can get <quote>lost</quote>. Please see the glossary if you want to know what <glossterm linkend="wrapping">wrapping</glossterm> is.</para></listitem>
304 <title>Commands to clean up</title>
305 <para>There are two commands to clean up the canvas after you have made a mess.</para>
307 <title>clear (cr)</title>
311 <listitem><para><screen>clear</screen>
312 With <userinput>clear</userinput> you can clean all drawings from the canvas. All other things remain: the position and angle of the turtle, the canvascolor, the visibility of the turtle, and the canvas size. <userinput>clear</userinput> can be abbreviated to <userinput>cr</userinput>.</para></listitem>
321 <listitem><para><screen>reset</screen>
322 <userinput>reset</userinput> cleans much more thoroughly than the <userinput>clear</userinput> command. After a <userinput>reset</userinput> command everything is like is was when you had just started &kturtle;. The turtle is positioned at the middle of the screen, the canvas color is white, and the turtle draws a black line on the canvas.</para></listitem>
329 <title>The turtle is a sprite</title>
330 <para>First a brief explanation of what sprites are: sprites are small pictures that can be moved around the screen, like we often see in computer games. Our turtle is also a sprite. For more info see the glossary on <glossterm linkend="sprites">sprites</glossterm>. </para>
331 <para>Next you will find a full overview on all commands to work with sprites.</para>
332 <para>[The current version of &kturtle; does not yet support the use of sprites other than the turtle. With future versions you will be able to change the turtle into something of your own design]</para>
333 <sect3 id="spriteshow">
337 <term>show (ss)</term>
338 <listitem><para><screen>show</screen>
339 <userinput>show</userinput> makes the turtle visible again after it has been hidden. <userinput>show</userinput> can be abbreviated to <userinput>ss</userinput>.</para></listitem>
343 <sect3 id="spritehide">
344 <title>hide (sh)</title>
348 <listitem><para><screen>hide</screen>
349 <userinput>hide</userinput> hides the turtle. This can be used if the turtle does not fit in your drawing. <userinput>hide</userinput> can be abbreviated to <userinput>sh</userinput>.</para></listitem>
356 <title>Can the turtles write?</title>
357 <para>The answer is: <quote>yes</quote>. The turtle can write: it writes just about everything you command it to.</para>
363 <listitem><para><screen>print X</screen>
364 The <userinput>print</userinput> command is used to command the turtle to write something on the canvas. <userinput>print</userinput> takes numbers and strings as input. You can <userinput>print</userinput> various numbers and strings using the <quote>+</quote> symbol. See here a small example:
368 print author + " started the KTurtle project in " + year + " and still enjoys working on it!"
374 <sect3 id="fontsize">
375 <title>fontsize</title>
378 <term>fontsize</term>
379 <listitem><para><screen>fontsize X</screen>
380 <userinput>fontsize</userinput> sets the size of the font that is used by <userinput>print</userinput>. <userinput>fontsize</userinput> takes one input which should be a number. The size is set in <glossterm linkend="pixels">pixels</glossterm>.</para></listitem>
387 <title>A command that rolls dice for you</title>
388 <para>There is one command that rolls dice for you, it is called <userinput>random</userinput>, and it is very useful for some unexpected results.</para>
392 <listitem><para><screen>random X,Y</screen>
393 <userinput>random</userinput> is a command that takes input and gives output. As input are required two numbers, the first (X) sets the minimum output, the second (Y) sets the maximum. The output is a randomly chosen number that is equal or greater then the minimum and equal or smaller than the maximum. Here a small example:
401 Using the <userinput>random</userinput> command you can add a bit of chaos to your program.</para></listitem>
407 <title>Input and feedback though dialogs</title>
408 <para>A dialog is a small pop-up window that provides some feedback or asks for some input. &kturtle; has two commands for dialogs, namely: <userinput>message</userinput> and <userinput>inputwindow</userinput></para>
410 <title>message</title>
414 <listitem><para><screen>message X</screen>
415 The <userinput>message</userinput> command takes a <link linkend="string">string</link> as input. It shows a pop-up dialog containing the text from the <link linkend="string">string</link>.
419 print author + " started the KTurtle project in " + year + " and still enjoys working on it!"
425 <sect3 id="inputwindow">
426 <title>inputwindow</title>
429 <term>inputwindow</term>
430 <listitem><para><screen>inputwindow X</screen>
431 <userinput>inputwindow</userinput> takes a <link linkend="string">string</link> as input. It shows a pop-up dialog containing the text from the string, just like the <link linkend="message">message</link>. But in addition to it also puts an input field on the dialog. Through this input filed the user can enter a <link linkend="number">number</link> or a <link linkend="string">string</link> which can be stored in a <link linkend="containers">container</link>. For example
433 in = inputwindow "What is you age?"
435 print "In 2003 you where " + out + " years old at some point."
437 When a user cancels the input dialog, or does not enter anything at all the <link linkend="containers">container</link> is emptied.</para></listitem>
447 <sect1 id="containers">
448 <title>Containers</title>
449 <para>Containers are letters or words that can be used by the programmer to store a number or a text. Containers that contain a number are called <link linkend="variables">variables</link>, containers that can contain text are called <link linkend="string">string</link>.</para>
451 <para>Containers that are not used contain nothing. An example:
455 This will print nothing. If we try to do <link linkend="math">math</link> with empty containers we will get errors.
458 <sect2 id="variables">
459 <title>Variables: number containers</title>
460 <para>Let us start with an example:
465 In the first line the letter <userinput>x</userinput> made into a variable (number container). As you see the value of the variable <userinput>x</userinput> is set to 3. On the second line the value is printed.</para>
466 <para> Note that if we wanted to print an <quote>x</quote> that we should have written
471 <para>That was easy, now a bit harder example:
477 # the next command prints "2029"
480 # the next command prints "2004 plus 25"
481 print A + " plus " + B
483 # the next command prints "1979"
486 In the first two lines the variables <userinput>A</userinput> and <userinput>B</userinput> are set to 2004 and 25. On the third line the variable <userinput>C</userinput> is set to <userinput>A + B</userinput>, which is 2029. The rest of the example consists of 3 <userinput>print</userinput> commands with <userinput>backward 30</userinput> in between. The <userinput>backward 30</userinput> is there to make sure every output is on a new line. In this example you also see that variables can be used in <link linkend="math">mathematical calculations</link>.</para>
490 <title>Containers that contain text (strings)</title>
491 <para>In programming code the regular text is usually started and ended with quotes. As we have already seen:
493 print "Hello programmer!"
495 The regular is delimited with quotes. These pieces of regular text we call <link linkend="strings">strings</link>.</para>
496 <para>Strings can also be stored in <link linkend="containers">containers</link> just like <link linkend="number">numbers</link>
497 Strings are a lot like variables. The biggest difference is that they contain text in stead of numbers. For this reason strings cannot be used in <link linkend="math">mathematical calculations</link> and <link linkend="questions">questions</link>. An example of the use of strings:
500 name = inputwindow "Please enter your name..."
501 print x + name + ", how are you?"
503 On the first line the string <userinput>x</userinput> is set to <quote>Hello </quote>. On the second line the string <userinput>name</userinput> is set to the output of the <userinput>inputwindow</userinput> command. On the third line the program prints a composition of three strings on the canvas.</para>
504 <para>This program ask you to enter your name. When you, for instance, enter the name <quote>Paul</quote>, the program prints <quote>Hello Paul, how are you?</quote>. Please note that the plus (+) is the only math symbol that you can use with strings.</para>
509 <title>Can the Turtle do math?</title>
510 <para>Yes, &kturtle; will do your math. You can add (+), substract (-), multiply (*), and divide (/). Here is an example in which we use all of them:
516 print "a: "+a+", b: "+b+", c: "+c+", d: "+d
518 Do you know what value a, b, c and d have? Please note the use of the <link linkend="assignment">assignment</link> symbol <userinput>=</userinput>.</para>
519 <para>If you just want a simple calculation to be done you can do something like this:
523 <para>Now an example with parentheses:
525 print ( ( 20 - 5 ) * 2 / 30 ) + 1
527 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).</para>
530 <sect1 id="questions">
531 <title>Asking questions, getting answers...</title>
532 <para><link linkend="if"><userinput>if</userinput></link> and <link linkend="while"><userinput>while</userinput></link> are <link linkend="controlling-execution">execution controllers</link> that we will discuss in the next section. In this section we use the <link linkend="if"><userinput>if</userinput></link> command to explain questions.</para>
534 <title>Questions</title>
535 <para>A simple example of a question:
543 In this example the question is the <userinput>x > 5</userinput> part. If the answer to this question is 'true' the code between the brackets will be executed. Questions are an important part of programming and often used together with <link linkend="controlling-execution">execution controllers</link>, like <link linkend="if"><userinput>if</userinput></link>. All numbers and <link linkend="variables">variables</link> (number containers) can be compared to each other with questions.</para>
545 Here are all possible questions:
547 <title>Types of questions</title>
551 <entry><userinput>a == b</userinput></entry>
552 <entry>equals</entry>
553 <entry>answer is <quote>true</quote> if <userinput>a</userinput> equals <userinput>b</userinput></entry>
556 <entry><userinput>a != b</userinput></entry>
557 <entry>not-equal</entry>
558 <entry>answer is <quote>true</quote> if <userinput>a</userinput> does not equal <userinput>b</userinput></entry>
561 <entry><userinput>a > b</userinput></entry>
562 <entry>greater than</entry>
563 <entry>answer is <quote>true</quote> if <userinput>a</userinput> is greater than <userinput>b</userinput></entry>
566 <entry><userinput>a < b</userinput></entry>
567 <entry>smaller than</entry>
568 <entry>answer is <quote>true</quote> if <userinput>a</userinput> is smaller than <userinput>b</userinput></entry>
571 <entry><userinput>a >= b</userinput></entry>
572 <entry>greater than or equals</entry>
573 <entry>answer is <quote>true</quote> if <userinput>a</userinput> is greater than or equals <userinput>b</userinput></entry>
576 <entry><userinput>a <= b</userinput></entry>
577 <entry>smaller than or equals</entry>
578 <entry>answer is <quote>true</quote> if <userinput>a</userinput> is smaller than or equals <userinput>b</userinput></entry>
584 <para>Questions are <glossterm>highlighted</glossterm> with light blue in the <link linkend="the-code-editor">code editor</link>.</para>
587 <sect2 id="question-glue">
588 <title>Question Glue</title>
590 Question glue-words enable us to glue questions into one big question.
594 if (a < 5) and (b == 5) [
598 In this example the glue-word <userinput>and</userinput> is used to glue 2 questions (<userinput>a < 5</userinput>, <userinput>b == 5</userinput>) together. If one side of the <userinput>and</userinput> would answer <quote>false</quote> the whole question would answer <quote>false</quote>, because with the glue-word <userinput>and</userinput> both sides need to be <quote>true</quote> in order to answer <quote>true</quote>. Please do not forget to use the brackets around the questions!</para>
601 Here is a schematic overview; a more detailed explanation follows below:
603 <title>Question glue-words</title>
607 <entry><userinput>and</userinput></entry>
608 <entry>Both sides need to be 'true' in order to answer 'true'</entry>
611 <entry><userinput>or</userinput></entry>
612 <entry>If one of the sides is 'true' the answer is 'true'</entry>
615 <entry><userinput>not</userinput></entry>
616 <entry>Special case: only works on one question! Changes 'true' into 'false' and 'false' into 'true'.</entry>
622 <para>Question glue-words are <glossterm>highlighted</glossterm> with purple in the <link linkend="the-code-editor">code editor</link>.</para>
626 <para>When two questions are glued together with <userinput>and</userinput>, both sides of the <userinput>and</userinput> have to be 'true' in order to result in 'true'. An example:
630 if ((a < 10) and (b == 5)) and (a < b) [
634 In this example you see a glued question glued onto an other question.</para>
639 <para>If one of the two questions that are glued together with <userinput>or</userinput> is 'true' the result will be 'true'. An example:
643 if ((a < 10) or (b == 10)) or (a == 0) [
647 In this example you see a glued question glued onto an other question.</para>
652 <para><userinput>not</userinput> is a special question glue-word because it only works for one question at the time. <userinput>not</userinput> changes 'true' into 'false' and 'false' into 'true'. An example:
656 if not ((a < 10) and (b == 5)) [
661 print "not hello ;-)"
664 In this example the glued question is 'true' yet the <userinput>not</userinput> changes it to 'false'. So in the end <userinput>"not hello ;-)"</userinput> is printed on the <link linkend="the-canvas">canvas</link>.</para>
671 <sect1 id="controlling-execution">
672 <title>Controlling execution</title>
673 <para>The execution controllers enable you — as their name implies — to control execution.</para>
674 <para>Execution controlling commands are <glossterm>highlighted</glossterm> with dark green in a bold font type. The square brackets are mostly used together with execution controllers and they are <glossterm>highlighted</glossterm> with light green.</para>
677 <title>Have the turtle wait</title>
678 <para>If you have done some programming in &kturtle; you have might noticed that the turtle can be very quick at drawing. This command makes the turtle wait for a given amount of time.</para>
682 <listitem><para><screen>wait X</screen>
683 <userinput>wait</userinput> makes the turtle wait for X seconds.
691 This code draws a circle, but the turtle will wait half a second
692 after each step. This gives the impression of a slow-moving turtle.</para></listitem>
698 <title>Execute "if"</title>
703 <listitem><para><screen>if <link linkend="questions">question</link> [ ... ]</screen>
704 The code that is placed between the brackets will only be executed <userinput>if</userinput> the answer to the <link linkend="questions">question</link> is <quote>true</quote>. Please read for more information on <link linkend="questions">questions</link> in the <link linkend="questions">question section</link>.
708 print "x is greater than five!"
711 On the first line <userinput>x</userinput> is set to 6. On the second line the <link linkend="questions">question</link> <userinput>x > 5</userinput> is asked. Since the answer to this question is <quote>true</quote> the execution controller <userinput>if</userinput> will allow the code between the brackets to be executed</para></listitem>
717 <title>The "while" loop</title>
722 <listitem><para><screen>while <link linkend="questions">question</link> [ ... ]</screen>
723 The execution controller <userinput>while</userinput> is a lot like <link linkend="if"><userinput>if</userinput></link>. The difference is that <userinput>while</userinput> keeps repeating (looping) the code between the brackets until the answer to the <link linkend="questions">question</link> is <quote>false</quote>.
732 On the first line <userinput>x</userinput> is set to 1. On the second line the <link linkend="questions">question</link> <userinput>x < 5</userinput> is asked. Since the answer to this question is <quote>true</quote> the execution controller <userinput>while</userinput> starts executing the code between the brackets until the answer to the <link linkend="questions">question</link> is <quote>false</quote>. In this case the code between the brackets will be executed 4 times, because every time the fifth line is executed <userinput>x</userinput> increases by 1.</para></listitem>
738 <title>If not, in other words: "else"</title>
743 <listitem><para><screen>if question [ ... ] else [ ... ]</screen>
744 <userinput>else</userinput> can be used in addition to the execution controller <link linkend="if"><userinput>if</userinput></link>. The code between the brackets after <userinput>else</userinput> is only executed if the answer to the <link linkend="questions">question</link> that is asked is <quote>false</quote>.
749 print "x is greater than five!"
753 print "x is smaller than six!"
756 The <link linkend="questions">question</link> asks if <userinput>x</userinput> is greater than 5. Since <userinput>x</userinput> is set to 4 on the first line the answer to the question is <quote>false</quote>. This means the code between the brackets after <userinput>else</userinput> gets executed.</para></listitem>
762 <title>The "for" loop, a counting loop</title>
767 <listitem><para><screen>for <userinput>start point</userinput> to <userinput>end point</userinput> [ ... ]</screen>
768 The <userinput>for</userinput> loop is a <quote>counting loop</quote>, &ie; it keeps count for you.
775 Every time the code between the brackets is executed the <userinput>x</userinput> is increased by 1, until <userinput>x</userinput> reaches the value of 10. The code between the brackets prints the <userinput>x</userinput> multiplied by 7. After this program finishes its execution you will see the times table of 7 on the canvas.</para></listitem>
784 <title>Create your own commands with <quote>learn</quote></title>
785 <para><userinput>learn</userinput> is a very special command, because it is used to create your own commands. The command you create can take <glossterm linkend="input-output">input</glossterm> and return <glossterm linkend="input-output">output</glossterm>. Let us take a look at how a new command is created:
794 The new command is called <userinput>circle</userinput>. <userinput>circle</userinput> takes one <glossterm linkend="input-output">input</glossterm>, a number, to set the size of the circle. <userinput>circle</userinput> returns no <glossterm linkend="input-output">output</glossterm>. The <userinput>circle</userinput> command can now be used like a normal command in the rest of the code. See this example:
810 <para>In the next example, a command with a return value is created.
814 learn multiplyBySelf n [
819 i = inputwindow "Please enter a number and press OK"
820 print i + " multiplied by itself is: " + multiplyBySelf i
822 In this example a new command called <userinput>multiplyBySelf</userinput> is created. The input of this command is multiplied by itself and then returned, using the <anchor id="return" /><userinput>return</userinput> command. The <userinput>return</userinput> command is the way to output a value from a function you have created.