pascal cheat sheet for programmers 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 sheet for programmers

repeat statement(s) until condition;

Example 3: pascal cheat sheet for programmers

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

Example 4: pascal cheat sheet for programmers

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

Example 5: pascal cheat sheet for programmers

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

Tags:

Misc Example