Turing/Introduction

put "wasn't that easy?";

breakdown of syntax:

put - outputs string (in this case) following the put command

"..." - string, which was output. A string is essentially a sequence of characters.

Another example:

put "first line"
put "second line"

Here, the first "put" will print out the string "first line". Then the second "put" will print out the string "second line". Notice that the strings are on separate lines. This is because "put" prints out a newline after the string. "first line" will be printed, then a newline, then "second line" and finally a newline (what you get when you hit Enter).

Imagine you had a very long program. There might be many statements (a line of code that does something). Your code could become unreadable. This is where comments come in handy.

%This program asks for your name. Then it says that the program does not accept input.
put "What is your name?" %asks the user for their name
put "However, please don't enter you name. This program doesn't accept input." %tells user to not enter anything

You might have noticed "%" in several places in this code segment. To make a comment, you simply put "%", and everything after is a comment. Comments can even be placed after statements (but not before, as the statement would become part of the comment). The most common use is to explain code, and the function of a program. Another use is to temporarily stop a section of code from running by prefixing a "%" to the statements. This is known as commenting out.

Exercises:

1. Make a program that outputs a string on one line and then another one on the next.

2. Make the second example print out both strings on the same line, without removing the second put. Note: You will have to do some research on this.


Project: Turing
Previous: Turing — Turing/Introduction — Next: Variables and Types