, Introduction to Pascal with Mc Kenzie


Learn Pascal Programming with Mc Kenzie

Home | About | Comments | Lectures | Notice | Registration

My name is Dirk Mc Kenzie and while I believe that great programmers are born and not made I also believe that you can achieve just about anything you put your mind to. Some things may take a bit longer than others for us to master but if we get the fundamentals right we will astonish even ourselves with our accomplishments.

Having said that you can probably guess that it is my intention to focus on the basics. Drill the basics and you will develop confidence and skill. At times the going will get tough but if you stick with programming you can actually develop your character. So I want to encourage you to put your best foot forward and keep pressing forward until you achieve your main objective which should be to learn basic pascal code to solve simple problems. I think you can do it so now it is all up to you.

Pascal is a high-level programming language that was developed specifically to teach students structured programming techniques. It is a teaching language like Basic and while it is not difficult to learn you need to spend some time working with Pascal before you can master its syntax.

Having said that, you will need a pascal compiler installed on your computer inorder to write the source code but you do not need one right now so let us get the ball rolling.

Welcome to the Pascal World!

 

Dear Student

We need to keep a few things in mind while programming. The first and most important at this time is to remember that computers can not think for themselves. Programmers must be able to solve each problem before instructing a computer to follow specific steps to arrive at a solution. Put another way, If you can't solve a problem then do not even attempt to code a solution. At the very least you should have a general idea of how to arrive at a solution before sitting at the computer. Some may disagree with me on this point and insist that we must be able to solve every detail on paper first before coding but that has not been my experience. I guess it is a case of different strokes for different folks. You may have your own opinion on this also. All I ask is that you keep an open mind and remember there are usually a number of ways to solving a single problem. The programmer should chose one that is efficient in terms of memory usage and program code but not to the extent that your code becomes so cryptic that you have problems reading your own code.

Program One

This is a simple but complete pascal program which finds the sum of two numbers 13 and 12 then prints the output 25.

program addversion1(output);
begin
   writeln(13 + 12);
   end.

This program has two parts.

1. The Program Heading
2. The Body

1.0   The Program Heading starts with the word PROGRAM followed by the name of the program. Each program must have a name. The name of the program is chosen by the programmer who writes the program. The name of the program is followed by the word output which is within braces. Some versions of Pascal do not require this. Finally the heading ends with a semi-colon.

Here is a second version of the same program :

program addversion2;
begin
   writeln(13 + 12);
   end.

2.0    The body of the program starts with BEGIN followed by one or more statements and ends with the word END. Please remember that statements end with the semi-colon but the program ends with a full stop after the word END.

Program 1 has only one statement :

WRITELN(13 + 12);

WRITELN stands for "write a line".The WRITELN statement instructs Pascal to add 13 to 12 then print the sum of both numbers. It does not matter to Pascal whether capital letters are used or not.