![]() | Containers |
Prev | KTurtle's Logo Programming Reference | Next |
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 variables, containers that can contain text are called strings.
Containers that are not used yet are 0 by default. An example:
print NThis will print a 0.
Let's start with an example:
x = 3 print xIn the first line the letter x made into a variable (number container). As you see the value of the variable x is set to 3. On the second line the value is printed.
Note that if we wanted to print an “x” that we should have written
print "x"
That was easy, now a bit harder example:
A = 2004 B = 25 AB = A + B # the next command prints "2029" print AB backward 30 # the next command prints "2004 plus 25" print "" + A + " plus " + B backward 30 # the next command prints "1979" print A - BIn the first two lines the variables A and B are set to 2004 and 25. On the third line the variable AB is set to A + B, which is 2029. The rest of the example consists of 3 print commands with backward 30 in between. The backward 30 is there to make sure every output is on a new line. In this example you also see that variables can be used in mathematical calculations.
Strings are a lot like variables. The biggest difference is that strings cannot be used in mathematical calculations and questions. An example of the use of strings:
x = "Hello " name = inputwindow "Please enter your name..." print x + name + ", how are you?On the first line the string x is set to “Hello ”. On the second line the string name is set to the output of the inputwindow command. On the third line the program prints a composition of three strings on the canvas.
This program ask you to enter your name. When you, for instance, enter the name “Paul”, the program prints “Hello Paul, how are you?”. Please note that the plus (+) is the only math symbol that you can use with strings.
Prev | Home | Next |
KTurtle's Logo Programming Reference | Up | Can the Turtle do math? |