You are on page 1of 3

Procedures in Pascal

A procedure is a sub-program. Sub-programs enable the programmer to organise code


into useful reusable segments. Variables can be passed between procedures (these are
called parameters); and all procedures are called by the main program or by another
procedure.

Declaring Procedures

The syntax of a procedure is similar to that of a program.

Syntax:
Procedure Procedurename (parameter: data type, parameter: data type);

Begin;
Statements;
End;

Note: the end of a procedure is followed by a semi-colon, not by a full stop.

Calling Procedures

The procedure should be declared before the Begin of the main program and the
procedure name should be used to call the procedure from within the main program.

Syntax:
Program ProgramName (input, output);

Procedure ProcedureName (parameters);

Begin;
Statements;
End;

Begin;
ProcedureName;
End.
Using Procedures from other PAS files

Procedures can be stored in other files so as to avoid a cluttered program. If the program
is to use those procedures the file name needs to be included at the top of the program.

Syntax:
{$I Path\filename}

Example:
{$I U:\11sdd\edmond~1\example.pas}

Note: As Pascal is DOS based, it will not recognise more than 8 characters so the tilde
and numbers must be used to identify longer files.

You might also like