Structure of a Pascal Program (2)
Structure of a Pascal Program (2)
The Program heading is a single statement beginning with the word program. The heading
assigns a name to the program and lists the input and output streams in parentheses. The program
block is the body of the program. The block is divided into two distinct parts:
1. The variable and constant declaration section where all the variables and constant data
structures used by the program are defined (Shown in program as var and const).
2. The statement section is where all the action statements of the program are specified. The
statement section is encapsulated within beginning and end statements.
Begin and end are examples of keywords used in Pascal. Keywords (or reserved words) are
words that have special meaning in Pascal and can only be used in the predefined context. That
is:
they cannot be used as variable names or in any other context. Other key words are:
program, type, var, const, read, write, readln, and writeln.
When you are adding comments to your program they are included between parenthesis { } or
between (* *) and can span multiple lines.
When outputting text to the screen as oppose to pseudocode where double quotations are
used, in Pascal single quotations are used. For example: Writeln(‘I Love to Program’);
Below is a table comparing the keywords of a pseudocode versus the keywords used in Pascal
Code.
1) The word Start is used to begin an The word Begin is used to start a Pascal
algorithm program
2) The word Read is used to input values The words Read and Readln is used to input
values
6) To end an algorithm the word Stop is used To end a Pascal program the word End
followed by a full stop is used. (End.)
Example 1
Write an algorithm to read three numbers and find the average of the numbers and output the
average of the numbers.
Pseudocode Version
Algorithm Average