This is a very simple short lesson. It will simply consist of making text display on the screen. Now in your Turing IDE type:
put "Hello World"
Now run your program. You should now see "Hello World" on the screen. Lets play around with this now. What happens if I where to change the code as follows?
put "Hello " put "World"
When this runs you should notice that "Hello" and "World" are now on separate lines. Now lets try making it look like the first one (when the program runs) but keep the two put statements on two lines.
put "Hello " .. put "World"
Now run your program. Looks like the first one, right? Well this will require an explanation of how the put command works. By default the cursor starts at the top left of the screen then scans left to right, top to bottom. When you say put "Hello " it writes "Hello " on the line where the cursor currently is then goes to a new line. By putting the .. at the end of the put statement it says write "Hello " to the screen but DO NOT go to the next line. Finally lets try this:
put "Hello ", "World"
Once again it looks like the first one. The comma allows you to concatenate the two strings together. This can be done with most data types as they are implicitly converted to strings for you at run-time.
For example, if you had a variable called "a", and you wanted to print out "The value of a is:" with the value of "a" after it, then you would write:
put "The value of a is: ", a
This makes the Turing IDE print out "The value of a is: ", and after it, it adds the value of "a". If "a" was 4, then "The value of a is: 4" would be printed out.
This concludes our first lesson.
|Previous: Introduction — Turing/Hello World — Next: Variables and Types|