AI Generate Pascal docs instantly

Pascal Cheat Sheet

Quick reference guide with copy-paste ready code snippets

Try DocuWriter Free

Getting Started

4 snippets

Basic 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 snippets

Declaration 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, Extended

Operators

4 snippets

Arithmetic 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 division

Comparison

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 equal

Logical

if (a > 0) and (b > 0) then
if (a > 0) or (b > 0) then
if not flag then
if (a > 0) xor (b > 0) then

Assignment

x := 10;           // Assignment
x := x + 1;        // Increment
Inc(x);            // Increment by 1
Dec(x);            // Decrement by 1
Inc(x, 5);         // Increment by 5

Tired of looking up syntax?

DocuWriter.ai generates documentation and explains code using AI.

Try Free

Control Flow

4 snippets

Conditional 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 snippets

Iteration 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 snippets

Subroutines 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);  // 8

Arrays & Records

5 snippets

Data 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 snippets

String operations

String Basics

var s: String;
s := 'Hello';
s := s + ' World';  // Concatenation

String Functions

Length(s)          // String length
Pos('ll', s)       // Find substring
Copy(s, 1, 5)      // Extract substring
UpCase(s)          // Uppercase
LowerCase(s)       // Lowercase

String Conversion

IntToStr(42)       // Integer to string
StrToInt('42')     // String to integer
FloatToStr(3.14)   // Float to string
StrToFloat('3.14') // String to float

More Cheat Sheets

FAQ

Frequently asked questions

What is a Pascal cheat sheet?

A Pascal cheat sheet is a quick reference guide containing the most commonly used syntax, functions, and patterns in Pascal. It helps developers quickly look up syntax without searching through documentation.

How do I learn Pascal quickly?

Start with the basics: variables, control flow, and functions. Use this cheat sheet as a reference while practicing. For faster learning, try DocuWriter.ai to automatically explain code and generate documentation as you learn.

What are the most important Pascal concepts?

Key Pascal concepts include variables and data types, control flow (if/else, loops), functions, error handling, and working with data structures like arrays and objects/dictionaries.

How can I document my Pascal code?

Use inline comments for complex logic, docstrings for functions and classes, and README files for projects. DocuWriter.ai can automatically generate professional documentation from your Pascal code using AI.

Code Conversion Tools

Convert Pascal to Other Languages

Easily translate your Pascal code to other programming languages with our AI-powered converters

Related resources

Stop memorizing. Start shipping.

Generate Pascal Docs with AI

DocuWriter.ai automatically generates comments, docstrings, and README files for your code.

Auto-generate comments
Create README files
Explain complex code
API documentation
Start Free - No Credit Card

Join 33,700+ developers saving hours every week