Output Introduction
Output is an essential part of every program. If you write a program that has no output, then your user will not feel like they have really done anything. In order to be user friendly, we need to include proper output.
Put Statement
Put is one of the simpler statements in Turing. It is used to display Strings or variables to the screen. In its simplist form, to looks like this:
put "Hello World"
or
put iNumber
This will display whatever is after 'put' to the screen for the user to see.
Put Multiple Values
In order to 'put' multiple values, you need to separate them with commas.
The result of:
var rNumber := 3.14159
var sName := "Sze"
put rNumber,sName
is:
3.14Sze
New Lines
In Turing, when you use the 'put' command, Turing will automatically put a new line character at the end of every 'put' statement. In order to stop this, we must follow the 'put' statement with " .. ". Normally, we would have:
The result of:
put "Hello "
put "There"
is:
Hello
There
But if we don't want the new line character there, we can write:
The result of:
put "Hello "..
put "There"
is:
Hello There
Since Turing automatically puts a new line character after every 'put' statement, we can write:
put ""
To create our own new line.
Output Formatting
Spacing
The Spacing, also called Field Width, specifies how many spaces the 'put' statement will take up. The number of spaces you want the 'put' statement to take up is written as:
put <AnyStringOrVariable> : <FieldWidth>
For example. say we wrote:
put "Hello" : 6
we would get:
_Hello
because Turing was told to write the string "Hello" (a 5 letter word), in 6 spaces. Because we wanted more spaces then what the word had, extra spaces had to be put before our string. If we picked a number smaller then 6, then it would automatically take up 5 spaces (since that is how long our string is).
Decimal Points
If you have a put statement that looks like
put rNumber : 0 : 2
Then whatever number is after the second colon (2, in this example), will be how many decimal points will be used to represent the number.
The result of:
var rNumber := 3.14159
put rNumber : 5 : 2
is:
_3.14
When you specify how many places after a decimal, Turing will automatically round up or down for you.
The result of:
var rNumber := 3.14519
put rNumber : 5 : 2
is:
_3.15