100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Pascal Program Structure

How every Pascal program is organized into a program heading, declaration sections, and a main statement block.

FoundationsBeginner9 min readJul 10, 2026
Analogies

Pascal Program Structure

Every Pascal program follows the same overall skeleton: an optional program heading naming the program, followed by one or more declaration sections (for constants, types, variables, and procedures or functions), and finally a single main block delimited by begin and end, with a period after the final end marking the program's true end. This fixed ordering is not just a style convention, the compiler enforces it, so you cannot declare a variable after the executable statements have started; all declarations must come first.

🏏

Cricket analogy: A Test match always follows the same fixed order, toss, then innings, then declaration, then result, and just as you can't bat before the toss is decided, Pascal won't let you declare a variable after the executable statements have begun.

The Program Heading and Uses Clause

The first line is typically 'program ProgramName;', which names the program for documentation purposes (Free Pascal doesn't strictly require it, but professional code always includes it). This is often followed by a 'uses' clause listing units the program depends on, such as 'uses SysUtils, Crt;', which brings in library routines like string formatting or screen control that aren't part of the core language. Units in Pascal work similarly to imports or includes in other languages: they expose a public interface of types, constants, and routines that the rest of the program can call.

🏏

Cricket analogy: Naming the program at the top is like a team sheet naming the captain before the toss, it's a formality that documents who's leading, and the uses clause is like naming which specialist bowlers, spin or pace, you're bringing into the squad.

Declaration Sections

Pascal groups declarations by kind, each introduced by its own keyword: 'const' for named constants that never change, 'type' for custom type definitions, 'var' for variables, and separate blocks for 'procedure' and 'function' definitions. These sections can appear multiple times and in a flexible order relative to each other, but every one of them must appear before the final main 'begin', and every variable used in the program must appear in some 'var' section first. This grouping makes a Pascal program's data shape visible at a glance near the top of the file, rather than scattered through the code.

🏏

Cricket analogy: A scorecard groups information by category, batting figures, bowling figures, extras, each in its own clearly labeled section, similar to how Pascal groups const, type, and var declarations each under their own keyword.

The Main Statement Block

After all declarations, the program's executable logic lives inside a single begin...end block, with statements separated by semicolons and the very last 'end' followed by a period to mark the end of the entire program (not a semicolon, which would be a common beginner mistake). Nested begin...end blocks are used throughout Pascal to group statements inside if, while, or for constructs, so understanding this outer program block is the same skill you'll reuse for every control structure later.

🏏

Cricket analogy: The main begin...end block is like the actual innings itself, bounded by the coin toss before it and the match result after, everything that actually happens is contained within those two boundaries.

pascal
program StructureDemo;
uses
  SysUtils;

const
  Pi = 3.14159;

type
  TColor = (Red, Green, Blue);

var
  radius: Real;
  favoriteColor: TColor;

function CircleArea(r: Real): Real;
begin
  CircleArea := Pi * r * r;
end;

begin
  radius := 2.5;
  favoriteColor := Blue;
  WriteLn('Area: ', CircleArea(radius):0:2);
end.

The final 'end.' with a period is special, it is the only place in a standard Pascal program where 'end' is followed by a period rather than a semicolon, and it signals the true end of the entire program to the compiler.

A very common beginner mistake is placing a variable declaration inside or after the main begin...end block. Pascal's compiler will reject this with an error, since all var declarations must appear in the declaration section before the main block starts, unlike languages such as C or Python that allow variables to be declared anywhere.

  • Every Pascal program follows: heading, uses clause, declaration sections, then a single main begin...end block.
  • The uses clause imports units like SysUtils or Crt that provide library routines.
  • Declarations are grouped by kind: const, type, var, and procedure/function blocks.
  • All declarations must appear before the main begin...end block starts.
  • The final 'end.' uses a period, not a semicolon, to mark the true end of the program.
  • Nested begin...end blocks are reused inside control structures like if, while, and for.
  • Declaring a variable after execution has started is a compile-time error in Pascal.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#PascalStudyNotes#PascalProgramStructure#Pascal#Program#Structure#Heading#StudyNotes#SkillVeris#ExamPrep