The Pascal programming language has several important words in it.
These are called
keywords. In example programs keywords will be displayed in bold. This
lesson will teach you some basic keywords and structure of your pascal programs.
A D V E R T I S E M E N T
It is optional to begin your program with the keyword 'Program', followed by
your program name. This keyword is useful only to you. It lets you identify what
the program does quickly and easily.
After this comes the keyword 'var'. This is followed by any variables you
wish to use in your program. If you are not using any variables then you do not
need the 'var' keyword. (More on variables in the next lesson.) Pascal will
report an error if you try to use the 'var' keyword without any variables.
After this comes the keyword 'begin'. This indicates the beginning of the
main part of your program. After this comes your program code. The end of the
program is indicated by the keyword 'end.'. Note the full stop after the word
'end'.
It is a good idea to commentyour code so you can understand what it
is doing if you look at it later. It is also important so that other people can
understand it also.
In pascal you can comment your code in two diffent ways. Either {to
start the comment and }to end the comment or (* to start the
comment and *)to end the comment.
eg.
Program DoNothing; {This line is optional}
var
begin
(*Note that comments can carry over
&multiple
&lines*)
end.
This program does absolutely and utterly nothing.
In fact this program will create an error on the begin command. It will say
'variable identifier expected'. This is because the var keyword should only be
included if you have variables to declare.
There are also several other keywords, which are optional and must come
before 'var'. Some of these are 'type', 'const' and 'uses'.
'Type' declares any variable structures - explained later.
'Const' declares any constant values to use throughout your program. These
are anything which is always the same, such as the number of days in the week.
Alternatively if you use a set value throughout your program, it is a good idea
to make this a constant value so that it can easily be changed if you later
decide to do so.
The 'Uses' keyword allows your program to use extra commands. These extra
commands are stored together in what is called a module or library. These
modules have names such as CRT, or GRAPH. Each modules contains several extra
commands. These commands will be related in some way. Eg. GRAPH contains extra
commands to do with graphics. CRT contains many general commands. (Even though
CRT stands for Cathode Ray Tube - ie. the screen)
eg.
uses crt, graph; {This means pascal allows you to uses the extra
commands in the crt and graph modules}
const
 InchesInFoot = 12; {These are some constants you might use}
 DaysInWeek = 7;
 e = 2.1718281828;
type
{Type definitions go here - don't worry about these yet}