pascal syntax cheat sheet code example
Example 1: pascal cheat sheet for programmers
program Addition;
uses
SysUtils;
var
LIn, LOut: Text;
LVar1, LVar2: integer;
LResult: integer;
begin
Assign(LIn, 'addin.txt');
Reset(LIn);
ReadLn(LIn, LVar1, LVar2);
Assign(LOut, 'addout.txt');
ReWrite(LOut);
LResult:= LVar1 + LVar2;
WriteLn(LOut, LResult);
CloseFile(LIn);
CloseFile(LOut);
end.
Example 2: pascal cheat sheett
VELOCITY_LIGHT = 3.0E=10;
PIE = 3.141592;
NAME = 'Stuart Little';
CHOICE = yes;
OPERATOR = '+';
Example 3: pascal cheat sheett
if - then statement
An if - then statement consists of a boolean expression followed by one or more statements.
2 If-then-else statement
An if - then statement can be followed by an optional else statement, which executes when the boolean expression is false.
3 nested if statements
You can use one if or else if statement inside another if or else if statement(s).
4 case statement
A case statement allows a variable to be tested for equality against a list of values.
5 case - else statement
It is similar to the if-then-else statement. Here, an else term follows the case statement.
6 nested case statements
You can use one case statement inside another case statement(s).
Example 4: pascal cheat sheett
procedure increment(var x: integer; by: integer);
begin
x := x + by;
end;
…
var
n: integer = 4;
begin
increment(n, 2);