Tuesday, January 20, 2009

How to make pascal program readable

The most important syntax is the semicolon after the program heading (which is used

as a separator) and the period after the word END (which terminates the program).

A common convention is to write Pascal keywords in uppercase and the user-invented

names (identifiers) in lowercase with the first letter capitalized. If the name consists of

more than one word (which is the case in this program), the first letter in each word is

capitalized. So, in Pascal programs you may see identifiers like:

Wages

Payroll

HoursWorkedPerWeek

This is just a convention to make your program readable, but Pascal compilers are not

case-sensitive. This means that you can write the entire program in lowercase as in

Example 1-2, or in uppercase as in Example 1-3. All three versions of the program will

compile and run.

{ ---------------------------- Example 1-2 ----------------------------- }

program hello_world;

begin

writeln(’Hello World!’)

end.

{ ----------------------------------------------------------------------- }

{ ----------------------------- Example 1-3 ----------------------------- }

PROGRAM HELLO_WORLD;

BEGIN

WRITELN(’Hello World!’)

END.

{ ---------------------------------------------------------------------- }

All blank lines, indentation, and spaces (except those following the Pascal keywords)

are optional, but it is a good programming habit to use this method to make your program

well-organized and readable.