0% found this document useful (0 votes)
21 views

Pascal Reference Sheet

pascal reference sheet

Uploaded by

wongclarissa25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Pascal Reference Sheet

pascal reference sheet

Uploaded by

wongclarissa25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Pascal Programming Reference Sheet

Built In Data Types & Literals Working with Strings


Integers Assignment (giving a string a value)
Integer, ShortInt, LongInt name := 'Fred';
(eg: 5, 10, 15) Concatenation (joining strings)
Floating Point Numbers name := name + ' Smith'
Single, Double, Extended Comparison
(eg: 3.1, 2.5, 2.1) if name = 'Fred Smith' then
Strings and Characters Construction from other types:
String, Char (eg: 'Hello', 'H') name := 'R' + IntToStr(2) + 'D'
Boolean + IntToStr(2);
Boolean (eg: True, False)

Simple Programming Statements Structured Programming Statements


Constant declaration If statement
const PI = 3.1415, MAX = 10; if done then … else …
Variable declaration
var name: String; age: Integer; case statement
Assignment case age of 1: …; 2: …; else …; end;
name := 'Fred'; age := MAX; while loop
Procedure Call while not done do …
WriteLn('Hello World', name, age);
repeat loop
Sequence of statements - grouped
repeat … until done;
begin … end;
For loop
for i := 0 to 10 do …
Declaring Functions & Procedures Boolean Operators and Other Statements
Declare a procedure with parameters: Comparison: equal, less, larger, not equal, less eq
procedure SayHello(toName: String); =, <, >, <>, <=, >=
var … begin … end; Boolean: And, Or and Not
and or not
Declare a functions:
functions ReadContact() : Contact; Skip an iteration of a loop
continue;
var … begin … result := …; … end;
End a loop early
Pass by reference: break;
procedure Swap (var v1, v2: Integer); End a function/procedure:
procedure Print(const friends: exit;
array of Contact);
Custom Types Arrays
Records Declaration
type Contact = record var scores: array [0..5] of Integer;
name: String; … var friends: array of Contact;
end; Access
var friend: Contact; scores[0] := 10;
friend.name := 'Fred'; friends[0] := ReadContact();
Enumerations Loop
for i := Low(scores) to High(scores) do
type Grade = (Pass, Credit, …); scores[i] := i * 100;
var myGrade: Grade;
myGrade := Pass;

Programs and Modules Other Things


Creating a program Reading from Terminal
program HelloWorld; ReadLn(age, name);
… // declare things here Writing to Terminal
WriteLn('Hello ', name, ' aged ', age);
begin … end. Comments
// single line
Using a module Compiling
program MyGame; fpc -S2 HelloWorld.pas
uses SwinGame, sgTypes, SysUtils;
begin … end;

Andrew Cain 1234567 Page 1 of 1

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy