Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Pascal is a high-level language named after a French philosopher, Blaise Pascal, who invented
the first adding machine.
In the first phase, the program’s source code (a series of statements used to instruct the computer
to perform a particular task) is created. The following line of source code instructs the computer
to print Hello World! on the screen:
The source code is typed and manipulated in a built-in program provided with Pascal, referred to
as an editor (displayed below).
In the second phase, the source code is compiled (by a program called a compiler), resulting in
the source code being converted to machine language (object code).
In the third phase (linking), the object code is converted to an executable image. This task is
performed by a program called the linker/loader.
In the final phase, the computer executes the program one instruction at a time.
276 CaFSET (Antigua) Office Workbook. Written by Richard and Jessie Lewis © 2009 by CaFSET (Antigua)
Introduction to Programming Lesson 2: Introduction to Pascal Programming
A compiler translates the source code into a form that you can run at a later date. Programs that
are produced by a compiler run very fast. The compiler does not have to be loaded on your
computer in order for the executable program to run.
A variable name can contain letters of the alphabet, decimal digits, and the underscore character
(_). However, the variable name must begin with a letter. Pascal is not case-sensitive, therefore
the variable names Gender and gender are seen as the same. Pascal has a number of Reserved
words (words that are reserved for, or are a part, of the language), which cannot be used as
variable names. For example, BEGIN, PROGRAM, or CHAR. It is useful to use variable
names which give an indication of the data they represent. In a Pascal program, variables are
declared as follows:
VAR
age : INTEGER;
salary : REAL;
gender : CHAR;
Variables with fixed values are called constants. Examples of values that remain constant
throughout a program are Income Tax (15%), or pi (3.14159). Constants are declared as follows:
CONST
IncTax = 0.15;
pi = 3.14159;
Program Layout
Below is the general format for a Pascal program:
VAR
declaration of variables;
CaFSET (Antigua) Office Workbook. Written by Richard and Jessie Lewis © 2009 by CaFSET (Antigua) 277
Introduction to Programming Lesson 2: Introduction to Pascal Programming
BEGIN
statement 1;
statement 2;
END.
INPUT indicates that data will be input via the keyboard, and OUTPUT indicates that data will
be output to the monitor.
Writeln(output list); outputs data to screen and then sends the cursor to a new line
so that any output following will begin on a new line
Write(output list); does not cause the cursor to advance to a new line
Input Statements
There are two (2) input statements used in Pascal:
Readln(input list); reads in the variables and then sends the cursor to a new line
Read(input list); does not cause the cursor to advance to a new line
The statement Readln(x); is storing the number that was entered in the variable named x. If the
user enters 6, that value would then be stored in x.
VAR
price : REAL; {price of item}
qty : INTEGER; {quantity purchased}
disc : REAL; (* discount allowed *)
278 CaFSET (Antigua) Office Workbook. Written by Richard and Jessie Lewis © 2009 by CaFSET (Antigua)