Pascal
Pascal is a structured programming language, it was at first created to teach programming language basic. Pascal is not very used in game and fangame making, but it's used as a learning language, to expand programming languages knowledge. Pascal language uses some specific rules to make it more like the english language:
Coding Examples
program HelloWorld;
begin
writeln('Hello, World!');
end.
Explanation of the code:
program HelloWorld;
HelloWorld is the program name, the program keyword is used before it as a key statement to run the program.
begin
This begins the main function of the program.
writeln('Hello, World!');
writeln is a function that prints on the screen the values received, in this case, what is inside the (' '). It will print Hello, World!. Every function or declaring must finish with an ";".
end.
This ends the main function of the program, note the . at the end of the world, this tells the compiler that the program's main function is over.
Here is a more complex program:
program PerfectNumbers;
uses crt;
var
until, x, add, i: integer;
begin
clrscr;
x := 0;
writeln('Perfect Numbers lower than : ');
Readln(until);
repeat
x := x + 1;
add := 0;
for i := 1 to x - 1 do
begin
if x mod i = 0 then
add := add + i;
end;
if add = x then
begin
writeln(x);
end;
until (x > until);
writeln('Press any key to close the program . . . ');
readkey;
end.
Explanation of the code:
uses crt;
Library used to manipulate DOS interface, in this case, it's going to clear the screen.
x := 0;
X variable recieves 0 as the initial value.
Readln(until);
Read variable from the keyboard.
repeat . . . until (x > until);
this will make anithing inside repeat until the expression in the end is true.
for i := 1 to x - 1 do begin . . . end;
For loop, i recieves the initial value of 1, the inside is repeated until x - 1, if x = 3, it will be done two times: 1 to 2.
readkey;
This reads any key from the keyboard, in this program is used to close the program after the user press any key.
Data types
Real : A real number.
Integer : An integer.
Char : One character.
Boolean : Type known as switch: true or false.
String : Array of char types.
Array : Set of numbers or any other data type stored in multiple locations.
a = Array [1..10] of Integer;
This creates an empty array, it's definers or flags are named from one to ten and its type is integer.