0% found this document useful (0 votes)
5 views

Structure of a Pascal Program (2)

A Pascal program consists of a program heading, a program block, and a program terminator. The program block includes variable and constant declarations and action statements, with keywords like 'begin' and 'end' defining its structure. Key distinctions in Pascal include the differences between 'read' and 'readln' for input, as well as 'write' and 'writeln' for output, with specific syntax rules for comments and statement termination.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Structure of a Pascal Program (2)

A Pascal program consists of a program heading, a program block, and a program terminator. The program block includes variable and constant declarations and action statements, with keywords like 'begin' and 'end' defining its structure. Key distinctions in Pascal include the differences between 'read' and 'readln' for input, as well as 'write' and 'writeln' for output, with specific syntax rules for comments and statement termination.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

STRUCTURE OF A PASCAL PROGRAM

A Pascal program has three distinct parts:


1. The program heading
2. The program block
3. The program terminator (a period)

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.

 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.

KEY DISTINCTIONS IN PASCAL

 The difference between READ and READLN


There is no difference between read and readln when working with numeric values such as 2, 6,
and 10. The difference applies when working with string values or characters on different lines
such as ‘A’, ‘B’ and ‘C’. When the computer reads the first letter (‘A’) if you use the keyword
READ the program will not move to the next line to read B and C. So the keyword READLN is
used to read in such values in another line.

 The difference between WRITE and WRITELN


The keyword Write outputs text or values to the screen in a single line leaving the cursor
positioned at the end of line. On the other hand Writeln which means write line, outputs text or
values to the screen in more than one line leaving the cursor at the beginning of the next line,
instead of at the end of the current line.
Please Note:
 All program statements and lines are terminated with a semi-colon (;), except the ‘begin’
and ‘end’ keywords. Program statements preceding an end statement do not require a
semi-colon (optional).

 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.

PSEUDOCODE KEYWORDS PASCAL KEYWORDS

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

3)Multiplication * and Division / Same

4) Assignment Symbol = or Assignment symbol :=

5) To display results/messages: Print, To display results: Write or Writeln


Display, Output

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

This algorithm finds the average of three numbers.


Start
Read num1, num2, num3
Average (num1 + num2 + num3)/3
Print “The average is”, Average
Stop
Program
Heading
Pascal Code
Comments shown in
Program Average_of_Numbers (input,output); parenthesis.
{This algorithm finds the average of three numbers}
var num1, num2, num3: integer; Declaring your variables
Begin and their data type
Readln(num1, num2, num3);
Average := (num1 + num2 + num3)/3; Program Block
Writeln(‘The average is:’, Average);
End.
Program
Terminator

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy