You are on page 1of 2

Programming with Pascal

Now that we have successfully written and ran our first program we can continue to advance with come
additional programming structures.

Program Tracking
There are times our program will compile but the result is undesired. These are known as run time
errors. We can isolate these errors by running a trace program which will allow us to run the program
line by line and see what each line really does. We can start the trace program by selecting the Run +
Pause. The program will run line by line until the Stop button is pressed. If there are any syntax errors
this option will not work as syntax errors will stop the program.

  Examples Explanation
Program
Header    
All programs must have a program heading.
Program name; Program Sample; The first word, program is compulstory.
Declarations    
A constant is a variable that does not change.
You assign a value to a constant when you
Const Const pi = 3.142; create it.
Var var:- Mark,count: This is called a variable declaration part.
integer; Test: real; Before you can use a variable you must first
Grade: char; declare it. Variable types include integer,
Title = "Hello"; real, character, literal (string), and array.
List: Array [1..5] of Integer;

Procedures and functions will go here before the main program.


Denotes the start of one or more
Begin Begin programming statements.
Statements    
Read(Mark); These include: input, output, conditional,
Writeln("Thank You"); assignment, loop.
If (Mark>30) Then Grade : ='P' Begin (of a compound statement) compound
Else Grade:= 'F'; statement two or more consecutive
Writeln (Grade); statements.
For count:= 1 to 5 DO
Begin
Test:= Mark * count;
Writeln(The test output is; test)
End;
 

Oxford Information Technology for CSEC page: 290-292


End. (with a full stop) indicates the very last
End. End. line or end of the program.

Punctuations
The semicolon is used to separate declarations and most statements. Semicolons separate individual
declarations and statements.

The keywords “begin” and “end” acts as brackets for multiple statements, so there is no semicolon after
begin but usually after end to show the end of the statement. There are some instances when no semi
colon is used after End, as shown below.

If (line >80)

Then Begin {performs the following two statements}

Writrln(‘This is over the line’);

Newline:= Newlin – line;

End {no semicolon}

Else writeln(‘This is within the line’, Newline);

If a semicolon is placed with the End, this would cause a syntax error for the IF-THEN-ELSE statement.
The last line of every Pascal program must have End. The full stop “.” Denotes the end of the program,
although you can still write comments.

Oxford Information Technology for CSEC page: 290-292

You might also like