Often we want to print statements like this:
length = 3 meters width = 2 meters
To do this we would use a combination of print, printNumber, and printNewLine. It looks like this:
print('length = '); printNumber(3); print(' meters'); printNewLine(); print('width = '); printNumber(2); print(' meters');
At first it might look like this approach is a bit too much work. Why not, for example, just write code like this:
print('length = 3 meters'); printNewLine(); print('width = 2 meters');
It is true that the above code would produce the same output. So why bother printing the numbers separately? The reason for this will become clear as we move into the following tutorials where we will see that these numbers can be replaced with variables that have changing values and need to be printed out this way.
Here we are simply showing the mechanics of printing text and numeric values on the same line.
These types of statements can be easily printed with the command printStatement, which does four things:
Let's assume a variable x holds a value of 5. Then this line:
printStatement('prefix', x, 'suffix');
You can skip the suffix. So this:
printStatement('x = ', x);
x = 5
This example shows how to print statements that include numeric values.
Next tutorial: Simple arithmetic
Here are some links to related articles at EZ Programing Demos: