Containers
Prev
Next

Containers

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 string.

Containers that are not used contain nothing. An example:

print N
This will print nothing. If we try to do math with empty containers we will get errors.

Variables: number containers

Let us start with an example:

x = 3
print x
In 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
C = A + B

# the next command prints "2029"
print C
backward 30
# the next command prints "2004 plus 25"
print A + " plus " + B
backward 30
# the next command prints "1979"
print A - B
In the first two lines the variables A and B are set to 2004 and 25. On the third line the variable C 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.

Containers that contain text (strings)

In programming code the regular text is usually started and ended with quotes. As we have already seen:

print "Hello programmer!"
The regular is delimited with quotes. These pieces of regular text we call strings.

Strings can also be stored in containers just like numbers 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 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
Next
Home


Would you like to comment or contribute an update to this page?
Send feedback to the TDE Development Team