pjhayward's Pascal Tutorial


pjhayward.net Home

Got a question?

Tutorial Home
Preparation
Lesson One - Sample Program
Lesson Two - Program Structure
Lesson Three - Data Types
and Constants
Lesson Four - Variables
Lesson Five - Text I/O
Lesson Six - Subroutines
Lesson Seven - Conditional
Statements
Lesson Eight - Arrays
Lesson Nine - Loops
Lesson Ten - Units
Lesson Two - Program Structure

You already have a little experience with the Pascal program structure. Now I'll go into some additional detail. Each program has a set structure. A template, if you will, of the program structure, goes like this:

program PROGRAMNAME;

const
// Constant Declarations 

type
// Type Declarations

var
// Variable Declarations

//Subroutine Declarations

begin
  // main program declaration
end.

A declaration is basically just a statement; For example:

const
  FirstLetter='a';



This "declares" that the constant named FirstLetter is equal to lowercase 'a'. Type and Variable declarations can be a bit more complicated, but all declarations follow the same basic principle. You are outlining for the compiler what some part of the program is, or what it is equal to.

The template above is not a legitimate pascal program. If you don't have any constants, types, or variables to declare, you should leave out the corresponding section. So, the above template, minus the unused sections, would give the following (working) program:

program PROGRAMNAME;
begin
end.
Obviously, this program doesn't actually DO anything. It just starts up, then exits. But it illustrates the most basic building block you need for a working program.

Next