Sign in Join
Wiki copytemporary

Basic Pascal Tutorial/Chapter 4/Procedures

Sent here from Procedures.

English · Français · Български · 中文(中国) · 日本語

4A - Procedures (author: Tao Yue, state: unchanged)

A procedure is a subprogram. Subprograms help reduce the amount of redundancy in a program. Statements that are executed over and over again but not contained in a loop are often put into subprograms.

Subprograms also facilitate top-down design. Top-down design is the tackling of a program from the most general to the most specific. For example, top down design for going from one room to another starts out as:

Then it is refined to

Just going to the door can be refined further:

This, of course, can be further refined to say how much exercise should be given to your cardiac myofibrils, and how much adenosine diphosphate should be converted to adenosine triphosphate by fermentation or aerobic respiration. This may seem to be too detailed, but for computer programming, this is, in effect what you have to do. The computer can't understand general statements -- you must be specific.

Main tasks should be contained in procedures, so in the main program, you don't have to worry about the details. This also makes for reusable code. You can just keep your procedures in one file and link that into your program.

A procedure has the same basic format as a program:

pascal
procedure Name;

const
  (* Constants *)

var
  (* Variables *)

begin
  (* Statements *)
end;

There is a semicolon (not a period) at the end.

To call the procedure from the main program, just use the name, like you would writeln.

pascal
 Name;

Procedures are very often used to output data. It's that simple (until the next lesson, of course).


From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 4/Procedures", as it stood on 2022-08-20 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Edited on wiki.freepascal.org by 7 people, 2007–2022

From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.

WhenWhoWhat changed
KeesNew page: 4A - Procedures A procedure is a subprogram. Subprograms help reduce the amount of redundancy in a program. Statements that are executed over and over again but not contained in a loop ar...
Kees
Kees
Kees
VincentText replace - "delphi>" to "syntaxhighlight>" (minor)
Jwdietrich
Swen (minor)
FTurtle
FTurtle
TrevFixed syntax highlighting (minor)
TrevFixed syntax highlighting (minor)
Kai BurghardtKai Burghardt moved page Procedures to Basic Pascal Tutorial/Chapter 4/Procedures: tidy up main name space: create subpage hierarchy for basic Pascal tutorial [cf. [[Special: PermaLink/149778#Cluttering... (minor)
Kai Burghardtbypass redirects [cf. discussion]
Kai Burghardtbypass language bar/categorization template redirect [cf. discussion] (minor)

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.