Now that the tools are set up, let’s look at the basic structure of a Pascal program.
1. The Core Program Structure
Every Pascal program follows a specific, rigid structure.
program MyFirstApp; // 1. Program Header (Optional but recommended name)
uses
SysUtils; // 2. Uses Clause (Libraries/Units you need)
var
// 3. Variable Declaration Section
MyNumber: Integer;
begin // 4. Program Execution Block (Mandatory)
// This is where the code starts running
Writeln('Hello, world!'); // Output the text to the console
Readln; // Waits for the user to press Enter (keeps console window open)
end. // 5. End Statement (Mandatory, ends with a period!)
2. Breakdown of Keywords
| Keyword | Purpose | Example |
program | The very first line, names the application. | program Calculator; |
uses | Declares external libraries (units) the program will use (e.g., SysUtils for utility functions). | uses Math; |
var | Used to declare variables before they are used in the main block. | var Name: String; |
begin | Marks the beginning of a code block (program body, procedure, or function). | begin ... |
end | Marks the end of a code block. The last end of the entire program must be followed by a period (.). | ... end; (block end) / ... end. (program end) |
3. Writing and Running Your First Code
- New Project: In Lazarus, select Project $\rightarrow$ New Project $\rightarrow$ Program (for a simple console application).
- Enter Code: Replace the default code with the “Hello, world!” example above.
- Compile and Run: Click the green Run button (or press F9).
- Result: A console window will pop up, display “Hello, world!”, and wait for you to press Enter before closing (due to
Readln).
