pascal syntax cheat sheet code example

Example 1: pascal cheat sheet for programmers

program Addition;

// Link the SysUtils file for access to file handling routines
uses
  SysUtils;

// Declare some variables
var
  LIn, LOut: Text;         // References to the input and output files
  LVar1, LVar2: integer;   // The two values that are to be added together
  LResult: integer;        // The result

begin

  // Open the input file
  Assign(LIn, 'addin.txt');
  Reset(LIn);

  // Read the input values
  ReadLn(LIn, LVar1, LVar2);

  // Open the output file
  Assign(LOut, 'addout.txt');
  ReWrite(LOut);

  // Calculate the result
  LResult:= LVar1 + LVar2;

  // Write to output file
  WriteLn(LOut, LResult);

  // Cleanup
  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);   // now n is 6