Search
 
SCRIPT & CODE EXAMPLE
 

PASCAL

pascal cheat sheett

type
days, age = integer;
yes, true = boolean;
name, city = string;
fees, expenses = real;
Comment

pascal cheat sheett

function name(argument(s): type1; argument(s): type2; ...): function_type;
Comment

pascal cheat sheett

var
  a: array[1..100] of integer;
Comment

pascal cheat sheett

Function Func_Name(params...) : Return_Value;
Procedure Proc_Name(params...);
Comment

pascal cheat sheett

type 
Books = record
   title: packed array [1..50] of char;
   author: packed array [1..50] of char;
   subject: packed array [1..100] of char;
   book_id: integer;
end;
Comment

pascal cheat sheett

Sr.No	Control Statement & Description
1	break statement
Terminates the loop or case statement and transfers execution to the statement immediately following the loop or case statement.

2	continue statement
Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.

3	goto statement
Transfers control to the labeled statement. Though it is not advised to use goto statement in your program.
Comment

pascal cheat sheett

procedure increment(var x: integer; by: integer);

  begin
    x := x + by;
  end;
…
var
  n: integer = 4;
begin
  increment(n, 2);   // now n is 6
Comment

pascal cheat sheett

function add(x: integer; y: integer): integer;
  begin
    add := x + y;
  end;
Comment

pascal cheat sheett

var
  a: array[1..100] of integer;
  sum: integer = 0;
…
for v in a do
  sum := sum + v;
Comment

pascal cheat sheett

type
   ch_array = array[char] of 1..26;
var
   alphabet: ch_array;
   c: char;

begin
   ...
   for c:= 'A' to 'Z' do
   alphabet[c] := ord[m];  
   (* the ord() function returns the ordinal values *)
Comment

pascal cheat sheett

var
choice: boolean;
Comment

pascal cheat sheett

procedure findMin(x, y, z: integer; var m: integer);
Comment

pascal cheat sheett

procedure name(argument(s): type1, argument(s): type 2, ... );
Comment

pascal cheat sheett

procedure yell(s: string, n: integer);
  var
    i: integer;
  begin
    for i := 1 to n do
      writeln(s);
  end;
Comment

pascal cheat sheett

const
identifier = constant_value;
Comment

pascal cheat sheett

VELOCITY_LIGHT = 3.0E=10;
PIE = 3.141592;
NAME = 'Stuart Little';
CHOICE = yes;
OPERATOR = '+';
Comment

pascal cheat sheett

readln (a, b, c);
s := (a + b + c)/2.0;
area := sqrt(s * (s - a)*(s-b)*(s-c));
writeln(area);        
Comment

pascal cheat sheett

(* This is a multi-line comments
   and it will span multiple lines. *)

{ This is a single line comment in pascal }
Comment

pascal cheat sheet for programmers

repeat statement(s) until condition;
Comment

pascal cheat sheet for programmers

with variable do begin statement(s) end;
with variable do statement;
Comment

pascal cheat sheet for programmers

while condition do begin statement(s) end;
while condition do statement;
Comment

pascal cheat sheet for programmers

if condition then begin statement(s) end;
if condition then statement;
Comment

pascal cheat sheett

age: integer = 15;
taxrate: real = 0.5;
grade: char = 'A';
name: string = 'John Smith';
Comment

pascal cheat sheett

program exPointers;
var
   number: integer;
   iptr: ^integer;
   y: ^word;

begin
   iptr := nil;
   y := addr(iptr);
   
   writeln('the vaule of iptr is ', y^);
end.
Comment

pascal cheat sheett

var
   p1, p2, ... : ptr-identifier;
Comment

pascal cheat sheett

Number is: 100
iptr points to a value: 100
Number is: 200
iptr points to a value: 200
45504
Comment

pascal cheat sheett

Book 1 title : C Programming
Book 1 author : Nuha Ali
Book 1 subject : C Programming Tutorial
Book 1 book_id : 6495407

Book 2 title : Telecom Billing
Book 2 author : Zara Ali
Book 2 subject : Telecom Billing Tutorial
Book 2 book_id : 6495700
Comment

pascal cheat sheett

type
record-name = record
   field-1: field-type1;
   field-2: field-type2;
   ...
   field-n: field-typen;
end;
Comment

pascal cheat sheett

var
   r1, r2, ... : record-name;
Comment

pascal cheat sheett

var
Books : record
   title: packed array [1..50] of char;
   author: packed array [1..50] of char;
   subject: packed array [1..100] of char;
   book_id: integer;
end;
Comment

pascal cheat sheett

type
record-ptr = ^ record-name;
record-name = record
   field-1: field-type1;
   field-2: field-type2;
   ...
   field-n: field-typen;
end;
Comment

pascal cheat sheett

type
   ptr-identifier = ^base-variable-type;
Comment

pascal cheat sheett

type
   color = ( red, black, blue, silver, beige);
   car_color = array of [color] of boolean;
var
   car_body: car_color;
Comment

pascal cheat sheett


Sr.No	Concept & Description
1	Multi-dimensional arrays
Pascal supports multidimensional arrays. The simplest form of the multidimensional array is the two-dimensional array.

2	Dynamic array
In this type of arrays, the initial length is zero. The actual length of the array must be set with the standard SetLength function.

3	Packed array
These arrays are bit-packed, i.e., each character or truth values are stored in consecutive bytes instead of using one storage unit, usually a word (4 bytes or more).

4	Passing arrays to subprograms
You can pass to a subprogram a pointer to an array by specifying the array's name without an index.
Comment

pascal cheat sheett

Element[1] = 101
Element[2] = 102
Element[3] = 103
Element[4] = 104
Element[5] = 105
Element[6] = 106
Element[7] = 107
Element[8] = 108
Element[9] = 109
Element[10] = 110
Comment

pascal cheat sheett

a: integer;
a: = alphabet['A'];
Comment

pascal cheat sheett

type
   ch_array = array[char] of 1..26;
var
   alphabet: ch_array;
Comment

pascal cheat sheett

type
   temperature = array [-10 .. 50] of real;
var
   day_temp, night_temp: temperature;
Comment

pascal cheat sheett

type
   vector = array [ 0..24] of real;
var
   velocity: vector;
Comment

pascal cheat sheett

type
   vector = array [ 1..25] of real;
var
   velocity: vector;
Comment

pascal cheat sheett

type
   array-identifier = array[index-type] of element-type;
Comment

pascal cheat sheett

   (* book 1 specification *)
   Book1.title  := 'C Programming';
   Book1.author := 'Nuha Ali '; 
   Book1.subject := 'C Programming Tutorial';
   Book1.book_id := 6495407;
Comment

pascal cheat sheett

(* book 1 specification *)
With Book1 do
begin
   title  := 'C Programming';
   author := 'Nuha Ali '; 
   subject := 'C Programming Tutorial';
   book_id := 6495407;
end;
Comment

pascal cheat sheett

not
and
or
Comment

pascal cheat sheett

var
   v: variant;
Comment

pascal cheat sheett


+

identity

-

negation

Comment

pascal cheat sheett

function sum(const a: array of integer): integer;

var
  s: integer = 0;
  v: integer;
begin
  for v in a do
    s := s + v;
  sum := v;
end;
Comment

pascal cheat sheett

// Return the first and last character of a string
function firstAndList(s: string; out first: char; out last: char);
begin
  first := s[1];
  last := s[length(s)];
end;
Comment

pascal cheat sheett

var
  a: integer = 4;
Comment

pascal cheat sheett

var
  x: integer;
  r: real;
Comment

pascal cheat sheett

const
  Seconds = 60;
Comment

pascal cheat sheett

type
  int = integer;
  array3 = array[1..3] of integer;

var
  i: int;
  a: array3;
Comment

pascal cheat sheett

repeat
  writeln(x);
  x := x * 2;
until x > 100;
Comment

pascal cheat sheett

while i > 0 do
  begin
    writeln(i);
    i := i div 2;
  end;
Comment

pascal cheat sheett

for i := 1 to n do
  begin
    writeln(i);
    writeln(i * 2);
  end;
Comment

pascal cheat sheett

Within the program exlocal
value of a = 100 b = 200 c = 300
Within the procedure display
Displaying the global variables a, b, and c
value of a = 30 b = 40 c = 70
Displaying the local variables x, y, and z
value of x = 10 y = 20 z = 30
Comment

pascal cheat sheett

var
  b: array[0..49] of boolean;
Comment

pascal cheat sheett

  writeln(p^);  // writes 7
  p^ := 8;
  writeln(i);   // writes 8
Comment

pascal cheat sheett

var
  p: ^integer;   // a pointer to an integer
Comment

pascal cheat sheett

var
  s: shape;

begin
  s.kind := rectangle;
  s.length := 5.0;
  s.height := 3.0;
  ...
Comment

pascal cheat sheett

type
  shapeType = (square, rectangle, circle);

  shape = record
    centerX, centerY: real;

    case kind: shapeType of
      square: (side: real);
      rectangle: (length, height: real);
      circle: (radius: real);
    end;
Comment

pascal cheat sheett

i := integer(d);
writeln(i);
d := day(i);
Comment

pascal cheat sheett

var
  a: array[1..100][1..20] of integer;
  b: array[1..100, 1..20] of integer;
Comment

pascal cheat sheett

a[44] := 33;

a[44] := a[44] + 1;
Comment

pascal cheat sheett

setLength(a, 100);
Comment

pascal cheat sheett

var
  a: array[1..3] of string = ('down', 'the', 'road');
Comment

pascal cheat sheett

var
boolean-identifier: boolean;
Comment

pascal cheat sheett

Operators	Operations
not	Bitwise NOT
and	Bitwise AND
or	Bitwise OR
xor	Bitwise exclusive OR
shl	Bitwise shift left
shr	Bitwise shift right
<<	Bitwise shift left
>>	Bitwise shift right
Comment

pascal cheat sheett

program exLocal; 
var
   a, b, c: integer;

begin
   (* actual initialization *)
   a := 10;
   b := 20;
   c := a + b;
   
   writeln('value of a = ', a , ' b =  ',  b, ' and c = ', c);
end.
Comment

pascal cheat sheett

var
age: 18 ... 100;
Comment

pascal cheat sheett

var
variable_name : type = value;
Comment

pascal cheat sheett

variable_name := value;
Comment

pascal cheat sheett

var
weekdays, holidays : days;
choice: yes;
student_name, emp_name : name;
capital: city;
cost: expenses;
Comment

pascal cheat sheett

var
age, weekdays : integer;
taxrate, net_income: real;
choice, isready: boolean;
initials, grade: char;
name, surname : string;
Comment

pascal cheat sheett

var
variable_list : type;
Comment

pascal cheat sheett

type
months = (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec);
Summer = Apr ... Aug;
Winter = Oct ... Dec;
Comment

pascal cheat sheett

const
P = 18;
Q = 90;
type
Number = 1 ... 100;
Value = P ... Q;
Comment

pascal cheat sheett

type
subrange-identifier = lower-limit ... upper-limit;
Comment

pascal cheat sheett

type
SUMMER = (April, May, June, July, September);
COLORS = (Red, Green, Blue, Yellow, Magenta, Cyan, Black, White);
TRANSPORT = (Bus, Train, Airplane, Ship);
Comment

pascal cheat sheett

var
var1, var2, ...  : enum-identifier;
Comment

pascal cheat sheett

type
enum-identifier = (item1, item2, item3, ... )
Comment

pascal cheat sheett

const
Identifier = contant_value;
Comment

pascal cheat sheett

Integer	-2147483648	2147483647	signed 32-bit
Cardinal	0	4294967295	unsigned 32-bit
Shortint	-128	127	signed 8-bit
Smallint	-32768	32767	signed 16-bit
Longint	-2147483648	2147483647	signed 32-bit
Int64	-2^63	2^63 - 1	signed 64-bit
Byte	0	255	unsigned 8-bit
Word	0	65535	unsigned 16-bit
Longword	0	4294967295	unsigned 32-bit
Comment

pascal cheat sheett

 type-identifier-1, type-identfier-2 = type-specifier;
Comment

pascal cheat sheett

All upper case letters (A-Z)

All lower case letters (a-z)

All digits (0-9)

Special symbols - + * / := , . ;. () [] = {} ` white space
Comment

pascal cheat sheett

var
A_Variable, B_Variable ... : Variable_Type;
Comment

pascal cheat sheett

$ fpc hello.pas
Free Pascal Compiler version 2.6.0 [2011/12/23] for x86_64
Copyright (c) 1993-2011 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling hello.pas
Linking hello
8 lines compiled, 0.1 sec

$ ./hello
Hello, World!
Comment

pascal cheat sheett

Hello, World!
Comment

pascal cheat sheett

program HelloWorld;
uses crt;

(* Here the main program block starts *)
begin
   writeln('Hello, World!');
   readkey;
end. 
Comment

pascal cheat sheett

Please enter your first name:
John
Please enter your surname:
Smith
Welcome to the world of Pascal John Smith
Comment

pascal cheat sheett

type
months = (January, February, March, April, May, June, July, August, September, October, November, December);
Var
m: months;
...
M := January;
Comment

pascal cheat sheett

Sr.No	Call Type & Description
1	Call by value
This method copies the actual value of an argument into the formal parameter of the subprogram. In this case, changes made to the parameter inside the subprogram have no effect on the argument.

2	Call by reference
This method copies the address of an argument into the formal parameter. Inside the subprogram, the address is used to access the actual argument used in the call. This means that changes made to the parameter affect the argument.
Comment

pascal cheat sheett

~, not,	Highest
*, /, div, mod, and, &	
|, !, +, -, or,	
=, <>, <, <=, >, >=, in	
or else, and then	Lowest
Comment

pascal cheat sheett

0 1 1 2	3 5 8 13 21 34
Comment

pascal cheat sheett

Enter a number:
5
Factorial 5 is: 120
Comment

pascal cheat sheett

n! = n*(n-1)!
   = n*(n-1)*(n-2)!
      ...
   = n*(n-1)*(n-2)*(n-3)... 1
Comment

pascal cheat sheett

Enter three numbers:
89 45 67
Minimum: 45
Comment

pascal cheat sheett

procedure name(argument(s): type1, argument(s): type 2, ... );
   < local declarations >
begin
   < procedure body >
end;
Comment

pascal cheat sheett

function max(num1, num2: integer): integer;
Comment

pascal cheat sheett

function name(argument(s): type1; argument(s): type2; ...): function_type;
local declarations;

begin
   ...
   < statements >
   ...
   name:= expression;
end;
Comment

pascal cheat sheett

Sr.No	Loop Type & Description
1	while-do loop
Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body.

2	for-do loop
Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.

3	repeat-until loop
Like a while statement, except that it tests the condition at the end of the loop body.

4	nested loops
You can use one or more loop inside any another while, for or repeat until loop.
Comment

pascal cheat sheett

&	Binary AND Operator copies a bit to the result if it exists in both operands.	(A & B) will give 12, which is 0000 1100
|	Binary OR Operator copies a bit if it exists in either operand.	(A | B) will give 61, which is 0011 1101
!	Binary OR Operator copies a bit if it exists in either operand. Its same as | operator.	(A ! B) will give 61, which is 0011 1101
~	Binary Ones Complement Operator is unary and has the effect of 'flipping' bits.	(~A ) will give -61, which is 1100 0011 in 2's complement form due to a signed binary number.
<<	Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand.	A << 2 will give 240, which is 1111 0000
>>	Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand.	A >> 2 will give 15, which is 0000 1111
Comment

pascal cheat sheett

program exEnumeration;
type
beverage = (coffee, tea, milk, water, coke, limejuice);

var
drink:beverage;

begin
   writeln('Which drink do you want?');
   drink := limejuice;
   
   writeln('You can drink ', drink);
end.
Comment

pascal cheat sheett

and	Called Boolean AND operator. If both the operands are true, then condition becomes true.	(A and B) is false.
and then	It is similar to the AND operator, however, it guarantees the order in which the compiler evaluates the logical expression. Left to right and the right operands are evaluated only when necessary.	(A and then B) is false.
or	Called Boolean OR Operator. If any of the two operands is true, then condition becomes true.	(A or B) is true.
or else	It is similar to Boolean OR, however, it guarantees the order in which the compiler evaluates the logical expression. Left to right and the right operands are evaluated only when necessary.	(A or else B) is true.
not	Called Boolean NOT Operator. Used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make it false.	not (A and B) is true.
Comment

pascal cheat sheett

=	Checks if the values of two operands are equal or not, if yes, then condition becomes true.	(A = B) is not true.
<>	Checks if the values of two operands are equal or not, if values are not equal, then condition becomes true.	(A <> B) is true.
>	Checks if the value of left operand is greater than the value of right operand, if yes, then condition becomes true.	(A > B) is not true.
<	Checks if the value of left operand is less than the value of right operand, if yes, then condition becomes true.	(A < B) is true.
>=	Checks if the value of left operand is greater than or equal to the value of right operand, if yes, then condition becomes true.	(A >= B) is not true.
<=	Checks if the value of left operand is less than or equal to the value of right operand, if yes, then condition becomes true.	(A <= B) is true.
Comment

pascal cheat sheett

+	Adds two operands	A + B will give 30
-	Subtracts second operand from the first	A - B will give -10
*	Multiplies both operands	A * B will give 200
/	Divides numerator by denominator	B / A will give 2
%	Modulus Operator and remainder of after an integer division	B % A will give 0
Comment

pascal cheat sheett

Arithmetic operators
Relational operators
Boolean operators
Bit operators
Set operators
String operators
Comment

pascal cheat sheett

Enter the radius of the circle
23
The circumference of the circle is 144.51
Comment

pascal cheat sheett

Enter your marks(1 - 100): 
100
Enter your grade(A - E):
A
Marks: 100 Grade: A
Comment

pascal cheat sheett

var
subrange-name : lowerlim ... uperlim;
Comment

pascal cheat sheett

var
marks: 1 ... 100;
grade: 'A' ... 'E';
age: 1 ... 25;
Comment

pascal cheat sheett

Which drink do you want?
You can drink limejuice
Comment

pascal cheat sheett

type
   rfile = file of real;
   ifile = file of integer;
   bfile = file of boolean;
   datafile = file of record
   arrfile = file of array[1..4] of integer;

var
   marks: arrfile;
   studentdata: datafile;
   rainfalldata: rfile;
   tempdata: ifile;
   choices: bfile;
Comment

PREVIOUS NEXT
Code Example
Powershell :: windows 10 debloat 
Powershell :: Take ownership of a file 
Powershell :: How to display firewall rule ports with powershell 
Powershell :: powershell get my documents folder 
Gdscript :: godot close game 
Gdscript :: godot make string all uppercase 
Gdscript :: godot print enum name 
Clojure :: clojure write file 
Lisp :: common lisp ide macos 
Assembly :: array month name 
Assembly :: custom color bootstrap buttonm 
Assembly :: Generate random strings only with uppercase letters and digits in Python 
Assembly :: how to listen for changes on an ObservableMap 
Assembly :: why assembly language use register 
Javascript :: jquery vslidation remove spaces from input 
Javascript :: js on page ready 
Javascript :: open ilnk target js 
Javascript :: refresh window js 
Javascript :: jquery accept only excel file 
Javascript :: check if a variable is undefined jquery 
Javascript :: media query js 
Javascript :: change input placeholder text jquery 
Javascript :: get current url js 
Javascript :: convert to objectid mongoose 
Javascript :: javascript async delay 
Javascript :: javascript refresh page every 30 seconds 
Javascript :: how to change a css variable with javascript 
Javascript :: hide header react navigation 
Javascript :: listing dir by nodejs 
Javascript :: javascript celcius to farenheit 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =