TURING LANGUAGE QUICK REFERENCE

Declarations:
var variablename : variabletype
tell the program that the specified variable is of the type variabletype. Variabletype can be either int, real, string

var postalcode : string(6) says that postalcode is a string variable that is 6 characters long

var i : int :=1 says that i is an integer variable and is initially set to equal 1

Input Statements: (from keyboard)
get variablename get information from the keyboard and store it in location variablename

get variablename : * means get a whole line of input

getkey waits until any key is pressed

include "u-string.t" (you can include code/subroutines that you use frequently - to change case, for example).

Output Statements: (to screen)
put "text"   prints the text inside the quotes on the screen

put name, " lives at ", address     prints the variables name and address with the text "lives at" in between them
put "Enter number: " ..     prints the text, then leaves the cursor after the text, so that the next characters appear there

locate (row, col)   positions the cursor to the row and column specified

cls clears the screen

Assignment Operators:
variablename := expression
:= is used to assign the results of some expression to the variable on the left.
(e.g. days := years * 365 )

counter += 1 adds one to the variable called counter.
This is identical to counter := counter + 1

j - = 5 decrements j by 5 (subtracts 5 from j)


Control Structures:

  1. Conditional statements:

    1. if expression then
         if expression is true (or equal to 1) then do the statements below
      statements
      else if this is optional
      more statements
      else
      (this is optional)
      more statements
      end if
    2. case variablename of
        Case statements are used to choose between a large number of choices.
        It is easier to read than a lot of if statements
      label value:
        In Turing, the values cannot be variables.   Turing also requires that one of the variables be matched.
      statements
      label
      value: statements label :
         This final label with no value is the default action if no other label matches the variable.
      statements
      end case

  2. Loops:

    1. for loops
      for i : 1 .. n    loop through the statements n times.
      statements
         the variable "i" can be used in statements
         "i" does not have to be initialized
      end for
    2. loop
        This loop will loop continuously until it executes an "exit" statement (if ever)
      statements if xxxx then exit end if
      statements
      end loop

String Functions:

Concatenation: use a '+' sign
name:= surname + ", " + firstname   would set name equal to something like Harwood, Michael

length(stringvar) returns the length of the string

tolower(stringvar) returns the lowercase version of the string (include "u-string.t")

toupper(stringvar) returns the uppercase version of the string (include "u-string.t")

index(stringvar,patt) returns the starting location of the pattern in the string.