CSCI 150

Home | | Course Schedule | | Assignments | | Lecture Notes

Pascal Notes

1) The basic Pascal Program
The format for a pascal program is as follows:

In place of {your code goes here} you would write the list of Pascal statements that you want executed in your program.

Comments are enclosed in brackets and are not part of the program. You should use comments to label your program with your name and section for every program you write. For example:

Note that all Pascal statements end with a semicolon and there is a period after the word 'end'.

2) Using writeln( )
Use the writeln( ) statement to write something to the monitor. The thing that you want to be written is enclosed in single quotes:

This statement will cause "My name is Sue" to be printed to the monitor.

3) Using variables and readln( )
Use readln( ) to read input from the keyboard. You will need to store that information somewhere, and we use a variable for that. A variable is a name we give to a location in memory where we can store a value. You can then use that name whenever you want to refer to that value.

The word var at the beginning indicates a list of variables follows. The word 'myName' is the name of a variable to be created and the word 'string' indicates the variable is a string of characters (i.e. text, as opposed to a number). When we use a + in a writeln( ) statement, it causes the text to be concatenated. Thus in the above example 'Hello' will be joined with the value of the variable, myName (which will contain whatever the user typed in). Note that there is a comment after the variable that gives a brief description of the variable.