Pascal is a classic, high-level, imperative, and procedural programming language. It was designed by Niklaus Wirth in the late 1960s and published in 1970. Named after the French mathematician and philosopher Blaise Pascal, it became a cornerstone of computer science education for decades.
Wirth designed Pascal to encourage structured programming and data structuring. At the time, languages like Fortran and COBOL were widely used but lacked the rigor needed to teach good programming habits.
Educational Roots: It was the primary language used to teach programming at universities throughout the 1970s and 80s.
Commercial Success: It evolved into Object Pascal, which powered Delphi, a popular tool for building Windows applications.
Influence: Pascal was the direct predecessor to Ada (used by the US Department of Defense) and influenced the design of many modern languages, including Java and C#.
Pascal is known for being "strongly typed," meaning it is very strict about how data is defined and used, which helps prevent bugs.
Readability: It uses English-like keywords (BEGIN, END, THEN, VAR) making it easy to read.
Structured Control: It supports IF-THEN-ELSE, WHILE-DO, and REPEAT-UNTIL structures.
Extensive Data Types: It introduced user-defined types and sets, allowing programmers to define complex data structures.
One-Pass Compilation: The language was designed so that a compiler could read the code from top to bottom just once, making compilation very fast on early hardware.
A Pascal program has a specific layout: the program header, variable declarations, and the body.
program HelloWorld;
begin
writeln('Hello, World!');
end.
Semicolons (;) : Used as statement separators.
Assignment (:=) : Pascal uses := for assignment, whereas = is used for equality testing.
Case Insensitivity: BEGIN, begin, and Begin are all treated the same.
The Period (.) : A period marks the very end of the program file.
Pros
Excellent for Learning: Teaches logical thinking and discipline.
Safety: The strict typing catches many errors at the compilation stage rather than at runtime.
Performance: Compiled Pascal code is nearly as fast as C.
Cons
Declining Popularity: It is rarely used for new mainstream commercial projects today (outside of Delphi environments).
Verbosity: Compared to Python or C, you often have to write more code to achieve the same result.
Rigidity: Some find its strictness frustrating for quick prototyping.
program MultiplyAndPrint;
uses
{ The 'printer' unit allows us to use the 'lst' file variable }
{ which represents the system default printer. }
printer;
var
num1, num2: real;
product: real;
procedure CalculateAndOutput(a, b: real);
var
res: real;
begin
res := a * b;
{ Output to the Monitor }
writeln('--- Results ---');
writeln('Input 1: ', a:0:2);
writeln('Input 2: ', b:0:2);
writeln('The Product is: ', res:0:2);
{ Output to the Printer }
{ 'lst' is a special file variable linked to the printer }
writeln(lst, 'Pascal Print Job');
writeln(lst, 'Input 1: ', a:0:2);
writeln(lst, 'Input 2: ', b:0:2);
writeln(lst, 'The Product is: ', res:0:2);
{ Sends a form feed to the printer to eject the page }
write(lst, chr(12));
end;
begin
{ Step 1: Accept inputs }
write('Enter the first number: ');
readln(num1);
write('Enter the second number: ');
readln(num2);
{ Step 2: Store and process via the routine }
CalculateAndOutput(num1, num2);
writeln('Output sent to printer. Press Enter to exit.');
readln;
end.