Getting Started
4 snippetsBasic Pascal syntax and structure
Hello World
program HelloWorld;
begin
WriteLn('Hello, World!');
end.Program Structure
program MyProgram;
uses SysUtils;
var
x: Integer;
begin
x := 10;
WriteLn(x);
end.Comments
// Single line comment
(* Multi-line
comment *)
{ Alternative
comment style }Units (Modules)
unit MyUnit;
interface
function Add(a, b: Integer): Integer;
implementation
function Add(a, b: Integer): Integer;
begin
Result := a + b;
end;
end.Variables & Data Types
5 snippetsDeclaration and types
Variable Declaration
var
age: Integer;
name: String;
price: Real;
flag: Boolean;Initialization
var
count: Integer = 0;
message: String = 'Hello';Constants
const
PI = 3.14159;
MAX_SIZE = 100;Type Declaration
type
TAge = 0..120;
TName = String[50];
TStatus = (Active, Inactive, Pending);Common Types
Integer, Real, Boolean, Char, String
Byte, Word, LongInt, Double, ExtendedOperators
4 snippetsArithmetic and logical operations
Arithmetic
result := a + b; // Addition
result := a - b; // Subtraction
result := a * b; // Multiplication
result := a div b; // Integer division
result := a mod b; // Modulo
result := a / b; // Real divisionComparison
if a = b then // Equal
if a <> b then // Not equal
if a > b then // Greater
if a < b then // Less
if a >= b then // Greater or equal
if a <= b then // Less or equalLogical
if (a > 0) and (b > 0) then
if (a > 0) or (b > 0) then
if not flag then
if (a > 0) xor (b > 0) thenAssignment
x := 10; // Assignment
x := x + 1; // Increment
Inc(x); // Increment by 1
Dec(x); // Decrement by 1
Inc(x, 5); // Increment by 5Tired of looking up syntax?
DocuWriter.ai generates documentation and explains code using AI.
Control Flow
4 snippetsConditional statements
If Statement
if age >= 18 then
WriteLn('Adult')
else
WriteLn('Minor');If-Else-If
if score >= 90 then
grade := 'A'
else if score >= 80 then
grade := 'B'
else if score >= 70 then
grade := 'C'
else
grade := 'F';Case Statement
case dayOfWeek of
1: WriteLn('Monday');
2: WriteLn('Tuesday');
3..5: WriteLn('Midweek');
6, 7: WriteLn('Weekend');
else
WriteLn('Invalid');
end;Compound Statement
if x > 0 then
begin
WriteLn('Positive');
Inc(count);
end;Loops
5 snippetsIteration constructs
For Loop
for i := 1 to 10 do
WriteLn(i);For Downto
for i := 10 downto 1 do
WriteLn(i);While Loop
while count < 10 do
begin
WriteLn(count);
Inc(count);
end;Repeat-Until
repeat
WriteLn(count);
Inc(count);
until count > 10;Break and Continue
for i := 1 to 100 do
begin
if i = 50 then Break; // Exit loop
if i mod 2 = 0 then Continue; // Skip even
WriteLn(i);
end;Procedures & Functions
4 snippetsSubroutines and return values
Procedure
procedure Greet(name: String);
begin
WriteLn('Hello, ', name, '!');
end;
// Call
Greet('Alice');Function
function Add(a, b: Integer): Integer;
begin
Result := a + b;
end;
// Call
x := Add(5, 3);Var Parameters
procedure Swap(var a, b: Integer);
var temp: Integer;
begin
temp := a;
a := b;
b := temp;
end;Default Parameters
function Power(base: Integer; exp: Integer = 2): Integer;
begin
Result := Round(Exp(exp * Ln(base)));
end;
y := Power(5); // 25
z := Power(2, 3); // 8Arrays & Records
5 snippetsData structures
Array Declaration
var
numbers: array[1..10] of Integer;
names: array[0..4] of String;Array Access
numbers[1] := 100;
WriteLn(numbers[1]);Dynamic Array
var
arr: array of Integer;
begin
SetLength(arr, 5);
arr[0] := 10;
end;Record
type
TPerson = record
name: String;
age: Integer;
end;
var
person: TPerson;
begin
person.name := 'John';
person.age := 30;
end;Array of Records
var
people: array[1..10] of TPerson;
begin
people[1].name := 'Alice';
people[1].age := 25;
end;String Handling
3 snippetsString operations
String Basics
var s: String;
s := 'Hello';
s := s + ' World'; // ConcatenationString Functions
Length(s) // String length
Pos('ll', s) // Find substring
Copy(s, 1, 5) // Extract substring
UpCase(s) // Uppercase
LowerCase(s) // LowercaseString Conversion
IntToStr(42) // Integer to string
StrToInt('42') // String to integer
FloatToStr(3.14) // Float to string
StrToFloat('3.14') // String to float