October 4, 2020•4 min read

The Parts and Structure of a Pascal Program

Like a letter that runs from the letterhead to the signature, Pascal code has writing rules and a structure it has to satisfy. Here is what goes where.

Read in Indonesian

After learning how to create and run Pascal code, this time we'll look at the basic structure of the Pascal language.

Like a letter that runs from the letterhead to the signature, Pascal code has writing rules and a structure it has to satisfy. Let's dig in.

Pascal Language Structure

Structured writing is one of Pascal's strengths. With structure, programmers can read a program easily.

We'll identify the structure of the earlier Hello World program. The code looks roughly like this.

PASCAL
program HelloWorld;
uses crt;
begin
  clrscr;
  writeln('Hello World');
  readln;
end.

1. The Program Title Section

The first part is the program title. A title always sits at the top. Short stories, news, even this tutorial, all have their own title at the top.

Do you know which part is the program title? It seems clear enough.

In Pascal the program title also sits at the very start of the program, in this code:

PASCAL
program HelloWorld;

The program title always starts with the word program. After that word comes the program title you want, and it ends with a semicolon (;).

PASCAL
program <Judul_Program>;

Writing a program title has a few rules. Break them and the program errors out. The rules are as follows.

  1. The program title must start with a letter (a-z / A-Z)
  2. No spaces are allowed inside the program title
  3. The underscore character can replace a space
  4. Digits can only appear in the middle or end of the title

The program title is actually optional. Still, it's better to include it.

2. The Declaration Section

Next comes the program declaration. You can think of this section as the Tools and Materials page of a recipe book.

The declaration section tells the computer what we need in order to run the program.

It sits right below the program title and above the begin keyword.

In the Hello World example above, the declaration section is this code.

PASCAL
uses crt;

That code orders the computer to use a "library" called crt. Think of a library as a "tool" for doing something. We'll do that "something" in the next section.

In the declaration section we can also type the "materials" we need, like constant, variable, type, procedure, and function.

We'll cover constant and variable in the next tutorial, while type, procedure, and function come later in the series.

3. The Main Program Section

The last section, and the most important one. This is where you write the program logic, using all the "tools" and "materials" from the declaration section.

Everything between begin and end is the main program section.

PASCAL
begin
  clrscr;
  writeln('Hello World');
  readln;
end.

Let's take this code from top to bottom.

  1. begin: orders the computer to start the program logic.
  2. clrscr: short for Clear Screen. This command clears the screen. clrscr is one of the uses of the crt "tool" from the declaration section.
  3. writeln('Hello World'): obvious, right? write means write, and ln is short for line. It orders the computer to write whatever sits inside the parentheses, in this case Hello World.
  4. readln: as before, read means read and ln means line. It orders the computer to read a line. So until you press enter, the computer waits here, and without it the output flashes past in an instant.
  5. end: the end of the program, stating that execution is complete. Then the program exits. Note the period (.), a sign used only at the very end of a program.

writeln and readln are the commands behind the input and output system. There are also write and read. We'll cover the output system in the next tutorial.

Using the Semicolon

From the program title to the main section, a semicolon always shows up. So what does the sign actually do?

In Pascal a semicolon marks the end of a statement. A statement is code that does one specific thing, like writing (writeln), reading (readln), or declaring.

"What happens if we drop the semicolon?"

The answer is that the program errors out at once. The computer can only read one block of commands at a time.

Drop the semicolon and the computer reads the first command and the second as a single command.

With the semicolon we can write long code on one line. This is valid code:

PASCAL
program HelloWorld; uses crt;
begin
  clrscr; writeln('Hello World'); readln;
end.

In that program clrscr, writeln, and readln are read as 3 separate statements, so no error occurs. The same holds for the title and declaration sections.

Writing code on one line is strongly discouraged, because it makes the program hard to read.

What's Next

That's all for this one, hope it helps.

For more on Pascal structure, head to the free pascal wiki page or search around this wide internet.

Next we'll cover Writing Comments in Pascal.

See ya 👋

Get better at shipping code.

Join the other developers getting tech updates, tips, and relaxed tutorials in their inbox every week.

Stay in the loop

Tech updates, coding tips, and relaxed insights straight to your inbox every week.

No spam. Unsubscribe anytime.

Read next

See all

For developers who learn by struggling

© 2026 Inva.dev.