Name: Pascal
Creator(s): Niklaus Wirth
Date: 1970
Website: Free Pascal
Pascal is an imperative and procedural programming language, designed by Niklaus Wirth as a small, efficient language intended to encourage good programming practices using structured programming and data structuring. It is named in honour of the French mathematician, philosopher and physicist Blaise Pascal.
Pascal became very successful in the 1970s, notably on the burgeoning minicomputer market. Compilers were also available for many microcomputers as the field emerged in the late 1970s. It was widely used as a teaching language in university-level programming courses in the 1980s, and also used in production settings for writing commercial software during the same period. It was displaced by the C programming language during the late 1980s and early 1990s as UNIX-based systems became popular, and especially with the release of C++.
Pascal needs to be compiled before execution. To compile a Pascal file called file.pas
use the command fpc file.pas
, then to run the output file use the command ./file
.
Variables in Pascal should be declared at the top of the file outside the main program block in a section denoted by the keyword var
. Variables are declared starting with a name and followed by a :
and a type. You can also assign the variables value using an =
sign. An example program with various dummy variables is shown below.
Program main;
var
index : integer;
num : integer = 42;
pi : real = 3.14;
letter : char = 'A';
name : string = 'Jacob';
begin
writeln('Do stuff here...');
end.
If/Else statements don't require brackets around the condition or curly braces around the body but do require the keyword then
after the condition.
if true then
writeln('True!')
else
writeln('False!');
The most common Pascal loops are for loops and while loops. A simple for loop can even be written on one line.
for index := 0 to 10 do writeln(index);
Loops with more internal logic that require more lines will also need the keywords begin
and end;
. A simple while loop example is shown below.
while index > 0 do
begin
index := index - 1;
writeln(index);
end;
Functions in Pascal are denoted with the keyword function followed by a name, a list of arguments in brackets and a return type. The function body is started with the keyword begin
and ended with the keyword end;
. The functions return value can be saved to a variable with the same name as the function.
function rect_area(num1, num2:integer):integer;
begin
rect_area := num1 * num2;
end;
- Awesome Pascal ~ A curated list of awesome Delphi, FreePascal and other Pascal frameworks, libraries, resources, and shiny things.