NASutils Knowledge BaseUnofficialPolski

Pascal · lesson 15 of 30 · Data, functions and the command lineName a block of lines

A const parameter can only be read. A var parameter lets the procedure change the caller's variable.

Programming on the NAS › Pascal in 30 lessons

15-procedures.pas Download 15-procedures.pas

program Procedures;

procedure Title(const Text: string);
var
  I: Integer;
begin
  WriteLn(Text);
  for I := 1 to Length(Text) do
    Write('-');
  WriteLn;
end;

procedure Swap(var A, B: Integer);
var
  Keep: Integer;
begin
  Keep := A;
  A := B;
  B := Keep;
end;

var
  First, Second: Integer;
begin
  Title('Disks');
  First := 1;
  Second := 2;
  Swap(First, Second);
  WriteLn('first ', First, ', second ', Second);
end.

Terminal

$ ./15-procedures
Disks
-----
first 2, second 1

Exercise

Write a procedure that prints a line of N stars.